home *** CD-ROM | disk | FTP | other *** search
/ Experimental BBS Explossion 3 / Experimental BBS Explossion III.iso / msdos / ansi_j.zip / ANSI.ASM next >
Assembly Source File  |  1993-05-15  |  125KB  |  2,255 lines

  1. ;------------------------------------------------------------------------;
  2. ;  ANSI.COM - Replacement for the ANSI.SYS console device driver.        ;
  3. ;  Unlike ANSI.SYS which must be installed at boot time, ANSI.COM        ;
  4. ;  can be installed and uninstalled at anytime.  Enhancements include    ;
  5. ;  a fast screen write and variable sized keyboard reassignment buffer.  ;
  6. ;                                                                        ;
  7. ;  Update 3/2/89 - Fix for DOS function 0Bh, Check Standard Input Status ;
  8. ;                      and STDIN in ANSI_INT_21 handler.                 ;
  9. ;                  Leading zero inserted for Device Status Report for    ;
  10. ;                      single digit cursor positions.                    ;
  11. ;                  INFORMATION typo 40 for 40H.                          ;
  12. ;                  WRITE_FAST modified to handle CR and LF instead of    ;
  13. ;                      WRITE_CHAR.                                       ;
  14. ;  Update 3/7/89 - Fix for CLS in graphics mode.          Version 1.2    ;
  15. ;                                                                        ;
  16. ;  Update 8/8/89 - STI added to INT 21 and 29 handler.    Version 1.3    ;
  17. ;:                                                                       ;
  18. ;: Update 01/01/90 - [KON | KOFF] and [PON | POFF] added  Version 1.31   ;
  19. ;:                   (all changes marked with ;: - Gary Meeker)          ;
  20. ;| Update 03/23/90 - /Q option added for no output when exectued  1.32   ;
  21. ;|                   (all changes marked with ;| - Gary Meeker)          ;
  22. ;; Update 05/16/90 - removed Syntax from output unless needed     1.33   ;
  23. ;;                   added /T test for load.                             ;
  24. ;;                   (all changes marked with ;; - Gary Meeker)          ;
  25. ;. Update 10/28/90 - Added /P nn top of screen protection mode    1.34   ;
  26. ;.                   (all changes marked with ;. - Gary Meeker)          ;
  27. ;@ Update 12/01/90 - Added PCBoard @X## color code support        1.35   ;
  28. ;@                   also added @Variable@ Support                       ;
  29. ;@                   added /S to load stats data from file               ;
  30. ;@                   (all changes marked with ;@ - Gary Meeker)          ;
  31. ;&                                                                       ;
  32. ;& Update 12/12/90 - My mistake, I didn't realize @X00 saved      1.36   ;
  33. ;&                   the color and @XFF restored it. Works now.          ;
  34. ;&                   Also made prompts return to start of line           ;
  35. ;&                   when cleared (like PCBoard does) & QON              ;
  36. ;&                   now changes @MORE@ & @PAUSE@ into @WAIT@            ;
  37. ;&                   (all changes marked with ;& - Gary Meeker)          ;
  38. ;                                                                        ;
  39. ;$ Update  4/22/91 - Change set cursor routine. If new position   1.37   ;
  40. ;$                   is off the screen use the last row or column.       ;
  41. ;$                   Added switch to not include PCB code.               ;
  42. ;$                   Corrected syntax display.                           ;
  43. ;$                   Modified CLS to honor protected (/P) lines.         ;
  44. ;$                   Modified /T to returned status switches.            ;
  45. ;$                   Modified /P to accept * to mean current row-1.      ;
  46. ;$                   (all changes marked with ;$ - Wayne Mingee)         ;
  47. ;                                                                        ;
  48. ;+ Update  9/19/91 - Allow ESC[p to clear all KB reassigns and    1.38   ;
  49. ;+                   ESC[np to clear single key reassign.                ;
  50. ;+                   ie: ESC[65p will reset ascii 65 to it's default [A] ;
  51. ;                                                                        ;
  52. ;^ Update 01/01/92 - Added XON/XOFF to control @X## color codes   1.39   ;
  53. ;^                   added support for finding relocated copies.         ;
  54. ;^                   This should allow LOADHI under DOS 5 or QRAM/QEMM   ;
  55. ;^                   (all changes marked with ;^ - Gary Meeker)          ;
  56. ;^                   (Was added to my 1.37 version 01/09/91 but now      ;
  57. ;^                   incorporated into this version as 1.39 to include   ;
  58. ;^                   changes by Wayne Mingee)                            ;
  59. ;                                                                        ;
  60. ;~ Update 05/15/93 - Added additional support for PCBoard 15.0    1.3j   ;
  61. ;~                   @Variable:xxx@ and new variables.                   ;
  62. ;~                   (all changes marked with ;~ - Gary Meeker)          ;
  63. ;                                                                        ;
  64. ;  PC Magazine - Michael J. Mefford                                      ;
  65. ;------------------------------------------------------------------------;
  66.  
  67. PCB            equ     0                     ;$ 1 = if PCB code wanted
  68.  
  69. _TEXT          SEGMENT PUBLIC 'CODE'
  70.                ASSUME  CS:_TEXT,DS:_TEXT,ES:_TEXT,SS:_TEXT
  71.                ORG     100H
  72. START:         JMP     INITIALIZE
  73.  
  74. ;                 DATA AREA
  75. SIGNATURE      DB      CR,SPACE,SPACE,SPACE,CR,LF
  76. COPYRIGHT      DB      'ANSI 1.3j (C) 1988 Ziff Communications Co.',CR,LF  ;^;~
  77. PROGRAMMER     DB      'PC Magazine ',BOX,' Michael J. Mefford',CR,LF,LF,'$'
  78.                DB      CTRL_Z
  79.  
  80. CR             EQU     13
  81. LF             EQU     10
  82. CTRL_Z         EQU     26
  83. SPACE          EQU     32
  84. BOX            EQU     254
  85. ESC_CHAR       EQU     27
  86. SINGLE_QUOTE   EQU     39
  87. DOUBLE_QUOTE   EQU     34
  88. BELL           EQU     7
  89. BS             EQU     8
  90. TAB            EQU     9
  91.  
  92. OFF            EQU     1
  93. ON             EQU     2
  94. SLOW           EQU     4
  95. FAST           EQU     8
  96. KOFF           EQU     16                         ;:
  97. KON            EQU     32                         ;:
  98. POFF           EQU     64                         ;:
  99. PON            EQU     128                        ;:
  100. XOFF           EQU     256                        ;^
  101. XON            EQU     512                        ;^
  102. STATUS_MASK    EQU     1111110000000001B          ;: Set Mask and Bit
  103. AND_MASK       EQU     1111111111111100B          ;^ Set Mask
  104. OR_MASK        EQU     0000000000000001B          ;^ Set Bit
  105.  
  106. ANSI_STATE     DW      ESC_STATE
  107. STATUS         DW      ON OR FAST OR KON OR PON OR XON    ;: ;^
  108. PARAMETERS     DB      'OFF',0,'ON',0,0,'SLOWFASTKOFFKON',0,'POFFPON',0 ;:
  109.                DB      'XOFFXON',0                                      ;^
  110. LAST_PARAMETER EQU     $ - PARAMETERS
  111.  
  112. multiplex_id   db      0dbh                    ;^ Program ID for multiplex int
  113. dos_version    dw      0                       ;^ DOS Version number
  114. int2fh         dd      -1                      ;^ Int 2f vector (DOS MULTIPLEX)
  115. OLD_INT_29     DW      ?,?
  116. OLD_INT_16     DW      ?,?
  117. OLD_INT_21     DW      ?,?
  118. if PCB                                            ;$
  119. OLD_INT_08     DW      ?,?              ;@ Save Timer Interupt
  120. endif                                             ;$
  121. ATTRIBUTE      DB      7
  122. if PCB                                            ;$
  123. SAVE_ATTRIBUTE DB      ?                ;& For saving attribute
  124. endif                                             ;$
  125. SAVE_POSITION  DW      0
  126. LINE_WRAP      DB      ON
  127. QUOTE_TYPE     DB      ?
  128. ESC_COUNT      DW      0
  129. NUMBER_COUNT   DW      0
  130. if PCB                                            ;~
  131. IGNORE         DW      0                ;~ Count of characters to ignore
  132. JUSTIFY        DB      'L'              ;~ Justification - Default L
  133. endif                                             ;~
  134.  
  135. COMMAND_TABLE  LABEL   BYTE
  136. DB   'H', 'A', 'B', 'C', 'D', 'f', 'n', 's', 'u', 'K', 'm', 'h', 'l', 'p', 'J'
  137. COMMAND_LENGTH EQU     $ - COMMAND_TABLE
  138.  
  139. DW   CURS_POSITION, CURSOR_UP,     CURSOR_DOWN, CURS_FORWARD, CURS_BACKWARD
  140. DW   HORZ_VERT_POS, DEVICE_STATUS, SAVE_CURSOR, RESTORE_CURS, ERASE_IN_LINE
  141. DW   SGR,           SET_MODE,      RESET_MODE,  REASSIGNMENT, CLS
  142. COMMAND_END    EQU     $ - 2
  143.  
  144. ATTRIBUTE_TABLE        LABEL    BYTE
  145. DB   00,01,04,05,07,08,30,31,32,33,34,35,36,37,40,41,42,43,44,45,46,47
  146. ATTRIBUTE_LENGTH       EQU      $ - ATTRIBUTE_TABLE
  147.  
  148. ;Format: AND mask,OR mask
  149. DB      000H,07H, 0FFH,08H, 0F8H,01H, 0FFH,80H, 0F8H,70H, 088H,00H
  150. DB      0F8H,00H, 0F8H,04H, 0F8H,02H, 0F8H,06H, 0F8H,01H, 0F8H,05H
  151. DB      0F8H,03H, 0F8H,07H, 08FH,00H, 08FH,40H, 08FH,20H, 08FH,60H
  152. DB      08FH,10H, 08FH,50H, 08FH,30H, 08FH,70H
  153. ATTRIBUTE_END          EQU      $ - 2
  154.  
  155. if PCB                                            ;$
  156. AT_VARIABLE_TABLE      LABEL BYTE                                          ;@
  157. DB   '@CLS@CLREOL@AUTOMORE@POFF@PON@QOFF@QON@BEEP@MORE@PAUSE@WAIT@HANGUP@' ;@
  158. DB   'DELAY@POS@'                                         ;~ For PCBoard 15.0
  159. DB   'OPTEXT@FIRSTU@FIRST@USER@CITY@HOMEPHONE@DATAPHONE@PROLTR@PRODESC@'   ;@
  160. DB   'EXPDATE@LASTDATEON@LASTTIMEON@INCONF@CONFNAME@BOARDNAME@'            ;@
  161. DB   'LASTCALLERNODE@LASTCALLERSYSTEM@EVENT@SYSOPIN@SYSOPOUT@BPS@NODE@'    ;@
  162. DB   'OFFHOURS@CARRIER@BICPS@RCPS@SCPS@'                  ;~ For PCBoard 15.0
  163. DB   'WHO@'                                               ;~
  164. DB   'SYSDATE@SYSTIME@FILERATIO@BYTERATIO@'                                ;@
  165. DB   'SECURITY@NUMCALLS@NUMTIMESON@TIMELEFT@TIMELIMIT@TIMEUSED@TOTALTIME@' ;@
  166. DB   'BYTESLEFT@BYTELIMIT@DLFILES@UPFILES@KBLEFT@KBLIMIT@CONFNUM@'         ;@
  167. DB   'CURMSGNUM@HIGHMSGNUM@LOWMSGNUM@MSGREAD@MSGLEFT@NUMBLT@NUMDIR@'       ;@
  168. DB   'DAYBYTES@MINLEFT@DLBYTES@UPBYTES@EXPDAYS@'                           ;@
  169. DB   'LMR@FREESPACE@RFILES@RBYTES@SFILES@SBYTES@'                          ;~
  170.  
  171. LAST_VARIABLE          EQU     $ - 1                                       ;@
  172.  
  173. JUMP_TABLE             LABEL WORD                                          ;@
  174. DW      CLS, ERASE_IN_LINE, AUTOMORE, AUTOOFF, AUTOOFF, QOFF, QON        ;&;@
  175. DW      BEEP, MORE, PAUSE, WAIT1, SKIP_IT                                  ;@
  176. DW      DELAY_IT, POS_IT                                                   ;~
  177.  
  178. ACTION_CODES EQU 14                     ;~ Length of Table
  179. STRING_CODES EQU ACTION_CODES+28        ;~
  180.  
  181. SUB_TABLE              LABEL BYTE                                          ;@
  182. DB      8,15,15,25,24,13,13,1,47                                           ;@
  183. DB      8,8,5,33,13,63                                                     ;@
  184. DB      52,52,5,5,5,6,2                                                 ;~ ;@
  185. DB      12,6,6,6,6,255                                                     ;~
  186. DB      0,0,4,4                                                            ;@
  187. DB      2,4,2,2,2,2,2                                                      ;@
  188. DB      4,4,2,2,4,4,2                                                      ;@
  189. DB      4,4,4,4,4,2,2                                                      ;@
  190. DB      4,2,4,4,2                                                          ;@
  191. DB      4,4,2,4,2,4                                                        ;~
  192.  
  193. SUB_LIST               LABEL BYTE                      ;@
  194. DB     '!OPTEXT!'                                      ;@ OPTTEXT
  195. DB     'GARY',0,0,0,0,0,0,0,0,0,0,0                    ;@ FirstU
  196. DB     'Gary',0,0,0,0,0,0,0,0,0,0,0                    ;@ First
  197. DB     'GARY MEEKER',0,0,0,0,0,0,0,0,0,0,0,0,0,0       ;@ User
  198. DB     'LAWRENCEVILLE, GA',0,0,0,0,0,0,0               ;@ City
  199. DB     '404 995-2699',0                                ;@ HomePhone
  200. DB     '404 962-1788',0                                ;@ DataPhone
  201. DB     'Z'                                             ;@ Proltr
  202. DB     'Zmodem       (Batch U/L and D/L)', 15 DUP (0)  ;@ ProDesc
  203. DB     '01-01-91'                                      ;@ ExpDate
  204. DB     '12-01-90'                                      ;@ LastDateOn
  205. DB     '08:00'                                         ;@ LastTimeOn
  206. DB     'Sysop (19) Conference ',0,0,0,0,0,0,0,0,0,0,0  ;@ InConf
  207. DB     'Sysop',0,0,0,0,0,0,0,0                         ;@ ConfName
  208. DB     'SHARP Technical Support Line BBS', 31 DUP (0)  ;@ BoardName
  209. DB     'MIKE BATE (RIVERDALE, GA)', 27 DUP (0)         ;@ LastCallerNode
  210. DB     'GARY MEEKER (LAWRENCEVILLE, GA)', 21 DUP (0)   ;@ LastCallerSystem
  211. DB     '04:30'                                         ;@ Event
  212. DB     '08:30'                                         ;@ SysopIn
  213. DB     '17:00'                                         ;@ SysopOut
  214. DB     '2400',0,0                                      ;@ bps           ;~
  215. DB     '1',0                                           ;@ Node
  216. DB     '00:00-23:59',0                                 ;~ Offhours
  217. DB     '38400',0                                       ;~ Carrier
  218. DB     '3500',0,0                                      ;~ BICPS
  219. DB     '1700',0,0                                      ;~ RCPS
  220. DB     '1800',0,0                                      ;~ SCPS
  221. DB     10,13                                           ;~ Who
  222. DB     ' (#)   Status                  User',10,13                              ;~
  223. DB     ' ---   ---------------------   -----------------------------',10,13     ;~
  224. DB     '   1   Available for CHAT      GARY MEEKER (LAWRENCEVILLE, GA)',10,13   ;~
  225. DB     '   2   No Caller this Node                                    ',10,13   ;~
  226. DB     26 DUP (0)                                      ;~
  227.  
  228. DD     48                                              ;@ FileRatio
  229. DD     128                                             ;@ ByteRatio
  230.  
  231. DW         120                                         ;@ Security
  232. DD       23946                                         ;@ numcalls
  233. DW        2107                                         ;@ numtimeson
  234. DW          61                                         ;@ timeleft
  235. DW         121                                         ;@ timelimit
  236. DW          59                                         ;@ timeused
  237. DW          59                                         ;@ totaltime
  238. DD     9508313                                         ;@ bytesleft
  239. DD    10238976                                         ;@ bytelimit
  240. DW          44                                         ;@ dlfiles
  241. DW        1234                                         ;@ upfiles
  242. DD        9285                                         ;@ KBLeft
  243. DD        9999                                         ;@ KBLimit
  244. DW          19                                         ;@ ConfNum
  245. DD        4734                                         ;@ CurMsgNum
  246. DD        4745                                         ;@ HighMsgNum
  247. DD           2                                         ;@ LowMsgNum
  248. DD        3456                                         ;@ MsgRead
  249. DD         987                                         ;@ MsgLeft
  250. DW          20                                         ;@ NumBlt
  251. DW          31                                         ;@ NumDir
  252. DD       30663                                         ;@ DayBytes
  253. DW          61                                         ;@ MinLeft
  254. DD      730663                                         ;@ DLBytes
  255. DD    12345678                                         ;@ UpBytes
  256. DW           0                                         ;@ ExpDays
  257. DD        4700                                         ;~ LMR
  258. DD    49356800                                         ;~ FreeSpace
  259. DW           8                                         ;~ RFiles
  260. DD      234567                                         ;~ RBytes
  261. DW          31                                         ;~ SFiles
  262. DD     3456789                                         ;~ SBytes
  263. SUB_LENGTH     EQU      $ - SUB_LIST
  264.  
  265. PAUSE_TIMER    DW      182                             ;@
  266. PAUSE_DELAY    DW      182                             ;@ 10 Seconds
  267. MORE_DELAY     DW      182 * 12                        ;@ 2 Minute
  268. WAIT_DELAY     DW      182 * 12                        ;@ 2 Minute
  269.  
  270. WAIT_PROMPT    DB      'press enter to continue'       ;@
  271. WAIT_LENGTH    DW      $ - WAIT_PROMPT                 ;@
  272. MORE_PROMPT    DB      '(61 min left), (H)elp, More?'  ;@
  273. MORE_LENGTH    DW      $ - MORE_PROMPT                 ;@
  274. COMMA          DB      0                               ;@
  275. Q_STATE        DB      0                               ;&
  276. endif                                             ;$
  277.  
  278. BIOS_ACTIVE_PAGE       EQU     62H
  279. ACTIVE_PAGE    DB      ?
  280. ADDR_6845      DW      ?
  281. BIOS_CRT_MODE          EQU     49H
  282. CRT_MODE       DB      ?
  283. CRT_COLS       DW      ?
  284. CRT_LEN        DW      ?
  285. CRT_START      DW      ?
  286. CRT_DATA_LENGTH        EQU     $ - CRT_MODE
  287. CURSOR_POSN    LABEL   WORD
  288. CURSOR_COL     DB      ?
  289. CURSOR_ROW     DB      ?
  290. CRT_ROWS       DB      ?
  291.  
  292. START_SCROLL   DB      0       ;. Number of rows to protect from scrolling up
  293.  
  294. DOS_INPUT      DB      OFF
  295. BUSY_FLAG      DB      OFF
  296. REASSIGN_FLAG  DB      OFF
  297. REMOVE_FLAG    DB      ON
  298. REASSIGN_COUNT DW      0
  299. REASSIGN_POS   DW      ?
  300. FUNCTION_16    DB      ?
  301. ZR             EQU     1000000B
  302.  
  303. ESC_BUFFER_SIZE      EQU     126
  304. REASSIGNMENT_DEFAULT EQU     200
  305. REASSIGNMENT_SIZE    DW      REASSIGNMENT_DEFAULT
  306. REASSIGNMENT_MAX     EQU     60 * 1024
  307. REASSIGN_END         DW      REASSIGNMENT_BUFFER
  308. BUFFER_END           DW      REASSIGNMENT_BUFFER + REASSIGNMENT_DEFAULT
  309.  
  310. ;                   CODE AREA
  311. ;************* INTERRUPT HANDLERS *************;
  312. ;------------------------------------------------------------------------------;
  313. ; INT 29 is an undocumented interrupt called by DOS for output to the console. ;
  314. ;------------------------------------------------------------------------------;
  315.  
  316. ANSI_INT_29    PROC    FAR
  317.                STI
  318.                PUSH    AX                      ;Save all registers.
  319.                PUSH    BX
  320.                PUSH    CX
  321.                PUSH    DX
  322.                PUSH    SI
  323.                PUSH    DI
  324.                PUSH    DS
  325.                PUSH    ES
  326.                PUSH    BP
  327.  
  328.                CLD                             ;All string operations forward.
  329.                MOV     BX,CS                   ;Point to our data segment.
  330.                MOV     DS,BX
  331.                MOV     ES,BX
  332.                CALL    ANSI_STATE              ;Call the current state of
  333.                                                ; the ANSI Esc sequence.
  334.                POP     BP
  335.                POP     ES
  336.                POP     DS
  337.                POP     DI
  338.                POP     SI
  339.                POP     DX
  340.                POP     CX
  341.                POP     BX
  342.                POP     AX                      ;Restore all registers and
  343.                IRET                            ; and return
  344. ANSI_INT_29    ENDP
  345.  
  346. ;------------------------------------------------;
  347.  
  348. ANSI_INT_21    PROC    FAR
  349.                PUSHF
  350.                CMP     AH,0BH                  ;If DOS function 0Bh (Check
  351.                JNZ     CK_INPUT                ; Standard Input Status)
  352.                CMP     CS:REASSIGN_FLAG,ON     ; and reassignment in progress,
  353.                JNZ     CK_INPUT                ; including a Device Status
  354.                CALL    DWORD PTR CS:OLD_INT_21 ; Request, then process call in
  355.                MOV     AL,0FFH                 ; case control break pressed;
  356.                IRET                            ; then return 0FFh for char ready
  357.  
  358. CK_INPUT:      CMP     AH,3FH                  ;Read from STDIN?
  359.                JNZ     CK_CONSOLE
  360.                OR      BX,BX
  361.                JZ      INPUT
  362.  
  363. CK_CONSOLE:    CMP     AH,0AH                  ;If DOS Int 21 functions Ah,
  364.                JZ      INPUT                   ; 7h, 1h or console input (6h)
  365.                CMP     AH,7                    ; then tell INT 16, DOS input
  366.                JZ      INPUT                   ; is active.
  367.                CMP     AH,1
  368.                JZ      INPUT
  369.                CMP     AH,8
  370.                JZ      INPUT
  371.                CMP     AH,6
  372.                JNZ     QUICK21_EXIT
  373.                CMP     DL,0FFH
  374.                JZ      INPUT
  375. QUICK21_EXIT:  POPF                              ;If not, let the original
  376.                JMP     DWORD PTR CS:OLD_INT_21   ; interrupt process the call.
  377.  
  378. INPUT:         POPF
  379.                MOV     CS:DOS_INPUT,ON           ;INT 16 handler flag.
  380.                PUSHF
  381.                CALL    DWORD PTR CS:OLD_INT_21   ;Emulate an interrupt.
  382.                MOV     CS:DOS_INPUT,OFF          ;Turn flag back off.
  383.                STI
  384.                RET     2                         ;Return with current flags.
  385. ANSI_INT_21    ENDP
  386.  
  387. ;-----------------------------------------------------------------;
  388. ; If we get here via a DOS console input call, any awaiting key   ;
  389. ; in keyboard buffer is checked to see if it is to be reassigned. :
  390. ;-----------------------------------------------------------------;
  391.  
  392. ANSI_INT_16    PROC    FAR
  393.                STI                             ;Interrupts back on.
  394.                PUSHF                           ;Preserve flags on stack.
  395.                PUSH    BP
  396.                PUSH    DS
  397.                PUSH    AX
  398.                PUSH    CS                      ;Point to our data.
  399.                POP     DS
  400.  
  401.                CMP     DOS_INPUT,OFF           ;If not called via a DOS
  402.                JZ      QUICK16_EXIT            ; console input call, exit.
  403.                CMP     BUSY_FLAG,ON            ;If already processing a call,
  404.                JZ      QUICK16_EXIT            ; exit.
  405.                CLD                             ;All string operations forward.
  406.                MOV     BP,SP                   ;Base reference to flags on stack
  407.                MOV     FUNCTION_16,AH          ;Save function request.
  408.                AND     AH,NOT 10H              ;Strip possible extended request.
  409.                JZ      GET_KEY                 ;If zero, it's wait for a key.
  410.                DEC     AH                      ;Else, decrement.  If zero it's
  411.                JZ      KEY_STATUS              ; key status, else exit.
  412.  
  413. QUICK16_EXIT:  POP     AX                      ;Restore registers and let
  414.                POP     DS                      ; original interrupt handler
  415.                POP     BP                      ; process the call.
  416.                POPF
  417.                JMP     DWORD PTR CS:OLD_INT_16
  418.  
  419. KEY_STATUS:    OR      BYTE PTR [BP+6],ZR      ;Assume none ready; ZR = 1.
  420. GET_KEY:       MOV     BUSY_FLAG,ON            ;Non-reentrant; flag busy.
  421.                POP     AX
  422.                PUSH    BX                      ;Save some more registers.
  423.                PUSH    CX
  424.                PUSH    DX
  425.                PUSH    SI
  426.                PUSH    DI
  427.                CMP     REASSIGN_FLAG,ON        ;Already in process of reassign?
  428.                JZ      CK_BUFFER               ;If yes, check kbd buffer.
  429.  
  430.                PUSHF                           ;Else, emulate an interrupt.
  431.                CALL    DWORD PTR OLD_INT_16
  432.                PUSHF                           ;Status call results in flags.
  433.                TEST    FUNCTION_16,1           ;Was it a status call?
  434.                JZ      CK_DUP                  ;If no, check key returned.
  435.                POPF                            ;Else, retrieve status results.
  436.                JZ      INT16_EXIT              ;If zero, no key waiting.
  437.                AND     BYTE PTR [BP+6],NOT ZR  ;Else, ZR = 0.
  438.                PUSHF                           ;PUSHF just to keep stack right.
  439.  
  440. CK_DUP:        POPF                            ;Fix stack.
  441.                TEST    STATUS,KOFF             ;:If KOFF then we don't do
  442.                JNZ     INT16_EXIT              ;:re-assignments
  443.                MOV     BX,AX                   ;Match procedure wants key in BX.
  444.                CALL    CK_MATCH                ;Check reassignment buffer.
  445.                JC      INT16_EXIT              ;If no match, exit.
  446.                MOV     AX,[DI]                 ;Else, retrieve string length.
  447.                SUB     AX,3                    ;Adjust for length word and match
  448.                ADD     DI,3                    ; byte; same for string pointer.
  449.                OR      BL,BL                   ;Extended key? ie. key = 0.
  450.                JNZ     STORE_COUNT             ;If no, save length and pointer.
  451.                DEC     AX                      ;Else, adjust for extended code.
  452.                INC     DI
  453. STORE_COUNT:   MOV     REASSIGN_COUNT,AX       ;Save string length.
  454.                MOV     REASSIGN_POS,DI         ;Save pointer to string.
  455.                MOV     REASSIGN_FLAG,ON        ;Flag that replacement in effect.
  456. CK_BUFFER:     TEST    FUNCTION_16,1           ;Was it a key wait function call?
  457.                JNZ     RETRIEVE                ;If no, key status; get it.
  458.                CMP     REMOVE_FLAG,OFF         ;Removed it from kbd buffer?
  459.                JZ      RETRIEVE                ;If yes, get reassignment.
  460.                MOV     AH,FUNCTION_16          ;Else, eat the replaced character
  461.                INT     16H                     ; via INT 16.
  462.                MOV     REMOVE_FLAG,OFF         ;Flag character eaten.
  463.  
  464. RETRIEVE:      MOV     DI,REASSIGN_POS         ;Retrieve pointer to string.
  465.                MOV     AX,[DI]                 ;Retrieve replacement character.
  466.                TEST    FUNCTION_16,1           ;Is it a key wait function call?
  467.                JZ      REMOVE                  ;If yes, bump pointer up one.
  468.                AND     BYTE PTR [BP+6],NOT ZR  ;If no, status call; ZR = 0
  469.                JMP     SHORT INT16_EXIT        ;All done.
  470.  
  471. REMOVE:        INC     REASSIGN_POS            ;Move pointer to next character.
  472.                DEC     REASSIGN_COUNT          ;One less character to replace.
  473.                JZ      REASSIGN_DONE           ;If end of string, reset flags.
  474.                OR      AL,AL                   ;Else, extended replacement?
  475.                JNZ     INT16_EXIT              ;If no, done here.
  476.                INC     REASSIGN_POS            ;Else adjust pointers.
  477.                DEC     REASSIGN_COUNT
  478.                JNZ     INT16_EXIT              ;End of string?
  479. REASSIGN_DONE: MOV     REASSIGN_FLAG,OFF       ;If yes, reset flags.
  480.                MOV     REMOVE_FLAG,ON
  481.  
  482. INT16_EXIT:    MOV     BUSY_FLAG,OFF           ;Reset the busy flag.
  483.                POP     DI                      ;Restore registers.
  484.                POP     SI
  485.                POP     DX
  486.                POP     CX
  487.                POP     BX
  488.                POP     DS
  489.                POP     BP
  490.                POPF                            ;Flags on stack have status
  491.                RET     2                       ; results; kill old flags.
  492. ANSI_INT_16    ENDP
  493. if PCB                                            ;$
  494. ANSI_INT_08    PROC    FAR                      ;@
  495.                CMP     CS:[PAUSE_TIMER],0       ;@
  496.                JE      SKIP_TIMER               ;@
  497.                DEC     CS:[PAUSE_TIMER]         ;@
  498. SKIP_TIMER:    JMP     DWORD PTR CS:OLD_INT_08  ;@
  499. ANSI_INT_08    ENDP                             ;@
  500. endif                                             ;$
  501. ;^============================================================================
  502. ;^ MUXINT processes calls to interrupt 2Fh
  503. ;^ Entry:  AH - Device ID
  504. ;^ Exit:   AL - 0FFh if AH = Alias device ID. Unchanged otherwise.
  505. ;^         ES - Code segment if AH = Alias device ID. Unchanged otherwise.
  506. ;^============================================================================
  507. muxint         proc    far                     ;^
  508.                cmp     ah,cs:[multiplex_id]    ;^ Check for program ID
  509.                je      muxint_1                ;^ Its us, indicate installed.
  510.                jmp     cs:[int2fh]             ;^ else pass the call on
  511. muxint_1:                                      ;^
  512.                mov     al,-1                   ;^ Indicate Alias installed
  513.                push    cs                      ;^ ES = installed code segment
  514.                pop     es                      ;^
  515.                iret                            ;^
  516. muxint         endp                            ;^
  517.  
  518. ;************* ANSI ESCAPE STATE ROUTINES ************* ;
  519.  
  520. ESC_STATE:     MOV     BX,OFFSET BRACKET_STATE ;Assume Esc character.
  521.                CMP     AL,ESC_CHAR             ;Is it Esc?  If yes, store
  522.                JZ      SHORT_JUMP              ; char. and next state.
  523. if PCB                                            ;$
  524.                CMP     DOS_INPUT,ON            ;@ Called via DOS Input?
  525.                JE      WRITE_CHAR2             ;@ Yes, Nevermind
  526.                MOV     BX,OFFSET ATX_STATE     ;@ No, Assume @ Character
  527.                CMP     AL,'@'                  ;@ Is it @? If yes, store
  528.                JZ      SHORT_JUMP              ;@ char. and next state.
  529. WRITE_CHAR2:
  530. endif                                             ;$
  531.                JMP     WRITE_CHAR              ;@ Else, normal char; write it.
  532. ;------------------------------------------------;
  533.  
  534. BRACKET_STATE: MOV     BX,OFFSET SPECIAL_STATE ;Assume left bracket.
  535.                CMP     AL,'['                  ;Is it left bracket?  If yes,
  536. SHORT_JUMP:    JZ      STORE_STATE             ;store char. and next state.
  537.                JMP     FLUSH_BUFFER            ;Else, flush Esc out of buffer.
  538.  
  539. ;---------------------------------------------------------------;
  540. ; Must process <ESC>[2J (CLS) regardless if ANSI.COM ON or OFF. ;
  541. ;---------------------------------------------------------------;
  542.  
  543. SPECIAL_STATE: MOV     BX,OFFSET CLS_STATE     ;Assume Erase in Display code.
  544.                CMP     AL,'2'                  ;Is it the '2' ?
  545.                JZ      STORE_STATE             ;If yes, progress to next state.
  546.                TEST    STATUS,OFF              ;Else, is ANSI OFF ?
  547.                JNZ     FLUSH_BUFFER            ;If yes, flush Esc, bracket.
  548.                MOV     BX,OFFSET PARAM_STATE   ;Else, check for first Set,
  549.                CMP     AL,'='                  ; Reset Mode characters of
  550.                JZ      STORE_STATE             ; '=' and '?'.
  551.                CMP     AL,'?'
  552.                JZ      STORE_STATE             ;If found, store.
  553.                JMP     SHORT DO_PARAMETER      ;Else, check other codes.
  554.  
  555. ;------------------------------------------------;
  556.  
  557. CLS_STATE:     CMP     AL,'J'                  ;Is it second character of CLS?
  558.                MOV     DI,OFFSET COMMAND_END   ;If yes, execute
  559.                JZ      EXECUTE                 ; Erase in Display procedure.
  560.                TEST    STATUS,OFF              ;ANSI OFF?  If yes, flush buffer.
  561.                JNZ     FLUSH_BUFFER            ; If not fall through to process.
  562.                MOV     BYTE PTR NUMBER_BUFFER,2 ;Store the previous 2.
  563. DO_PARAMETER:  MOV     ANSI_STATE,OFFSET PARAM_STATE  ;Parameter state.
  564.  
  565. ;------------------------------------------------;
  566.  
  567. PARAM_STATE:   CALL    CK_QUOTE                ;Is it single or double quotes?
  568.                JZ      STORE_STATE             ;If yes, store string state.
  569.                CMP     AL,';'                  ;Is it semi-colon delimiter?
  570.                JNZ     CK_NUMBER               ;If no, check if number.
  571.                INC     NUMBER_COUNT            ;Else, increment number count.
  572.                JMP     SHORT BUFFER_CHAR       ;Buffer the semi-colon.
  573.  
  574. CK_NUMBER:     CMP     AL,'0'                  ;Is it below 0 ?
  575.                JB      FLUSH_BUFFER            ;If yes, illegal; flush buffer.
  576.                CMP     AL,'9'                  ;Else, is it above 9 ?
  577.                JA      DO_COMMAND              ;If yes, check for command char.
  578.                CALL    ACCUMULATE              ;Else it's a number; accumulate.
  579.                JMP     SHORT BUFFER_CHAR       ;Buffer the character.
  580.  
  581. DO_COMMAND:    MOV     DI,OFFSET COMMAND_TABLE ;Point to legal ANSI commands.
  582.                MOV     CX,COMMAND_LENGTH       ;Number of commands.
  583.                REPNZ   SCASB                   ;Check for a match.
  584.                JNZ     FLUSH_BUFFER            ;If no match, flush sequence.
  585.                INC     NUMBER_COUNT            ;Else, increment for last number.
  586.                MOV     DI,OFFSET COMMAND_END   ;Point to appropriate command
  587.                SHL     CX,1                    ; processing procedure.
  588.                SUB     DI,CX
  589. EXECUTE:       CALL    GET_BIOS_DATA           ;Get cursor position data.
  590.                CALL    DS:[DI]                 ;Do command subroutine.
  591.                JMP     SHORT FLUSH_END         ;Clear buffer.
  592.  
  593. ;------------------------------------------------;
  594.  
  595. QUOTE_STATE:   CMP     AL,QUOTE_TYPE           ;Is it an ending string quote?
  596.                JNZ     BUFFER_CHAR             ;If no, buffer literal.
  597.                MOV     BX,OFFSET PARAM_STATE   ;Else, back to parameter parsing.
  598.  
  599. ;------------------------------------------------;
  600.  
  601. STORE_STATE:   MOV     ANSI_STATE,BX           ;Store the ANSI state.
  602.  
  603. ;------------------------------------------------;
  604.  
  605. BUFFER_CHAR:   MOV     DI,ESC_COUNT            ;Buffer the character in case
  606.                CMP     DI,ESC_BUFFER_SIZE      ; ending ANSI command is illegal.
  607.                JZ      FLUSH_BUFFER            ;If buffer full, flush.
  608.                ADD     DI,OFFSET ESC_BUFFER    ;Point to next buffer position.
  609.                STOSB                           ;Store the character.
  610.                INC     ESC_COUNT               ;Increment the sequence count.
  611.                RET
  612.  
  613. ;------------------------------------------------;
  614.  
  615. FLUSH_BUFFER:                                     ;$
  616. if PCB                                            ;$
  617.                CALL    BUFFER_CHAR             ;@ Buffer current character also!
  618. FLUSH_BUFF2:                                   ;@
  619. else                                              ;$
  620.                PUSH    AX                      ;Save the current character. Might need removal
  621. endif                                             ;$
  622.                MOV     SI,OFFSET ESC_BUFFER    ;Point to the sequence buffer.
  623.                MOV     CX,ESC_COUNT            ;Count of buffered characters.
  624. if pcb                                            ;~
  625. FLUSH_BUFF3:   PUSH    CX                      ;~
  626.                STC                             ;~Indicate LEFT PADDING
  627.                CALL    PAD_STRING              ;~
  628. endif                                             ;~
  629.  
  630. NEXT_FLUSH:    LODSB                           ;Retrieve one.
  631.                PUSH    CX                      ;Save counter and pointer.
  632.                PUSH    SI
  633.                CALL    WRITE_CHAR              ;Write character to screen.
  634.                POP     SI                      ;Restore counter and pointer.
  635.                POP     CX
  636.                LOOP    NEXT_FLUSH              ;Flush entire buffer.
  637. ife PCB                                           ;$
  638.                POP     AX                      ;@Retrieve last character.   Might need removal
  639.                CALL    WRITE_CHAR              ;@Write it also.             Might need removal
  640. endif                                             ;$
  641.  
  642. if  PCB                                           ;~
  643.                POP     CX                      ;~
  644.                CLC                             ;~Indicate RIGHT PADDING
  645.                CALL    PAD_STRING              ;~
  646. endif                                            ;~
  647.  
  648. FLUSH_END:     MOV     ESC_COUNT,0                   ;Reset counter.
  649.                MOV     ANSI_STATE,OFFSET ESC_STATE   ;Back to Esc state.
  650.                MOV     NUMBER_COUNT,0                ;Reset parameter counter.
  651.                PUSH    CS                            ;Point to our data.
  652.                POP     ES
  653.                MOV     DI,OFFSET NUMBER_BUFFER       ;Clear number buffer
  654.                MOV     CX,ESC_BUFFER_SIZE / 2        ; to zeros.
  655.                XOR     AX,AX
  656.                REP     STOSW
  657.                RET
  658. if PCB                                            ;$
  659. ;------------------------------------------------;@
  660. COLOR_STATE:   MOV     AH,AL                   ;^ Save character
  661.                CMP     AL,'0'                  ;@ Is it below 0 ?
  662.                JB      FLUSH_BUFFER            ;@ If yes, illegal; flush buffer.
  663.                CMP     AL,'9'                  ;@ Else, is it 0 - 9 ?
  664.                JBE     DO_COLOR                ;@ If yes, Make color.
  665.                CMP     AL,'A'                  ;@ Is it below A ?
  666.                JB      FLUSH_BUFFER            ;@ If yes, illegal; flush buffer.
  667.                CMP     AL,'F'                  ;@ Is it Above F ?
  668.                JA      FLUSH_BUFFER            ;@ If yes, illegal; flush buffer.
  669.                SUB     AL,7                    ;@ Else, adjust for Hex
  670. DO_COLOR:      CALL    ACCUM_COLOR             ;@ Accumulate Color.
  671.                MOV     AH,AL                   ;^ get saved character
  672.                INC     NUMBER_COUNT            ;@ Count the character
  673.                CMP     NUMBER_COUNT,2          ;@ Already got two?
  674.                JNE     SHORT BUFFER_CHAR   ;~;&;@ No, Buffer the character.
  675.                TEST    STATUS,OFF              ;@ Else, is ANSI OFF ?
  676.                JNZ     FLUSH_BUFFER            ;@ If yes, flush Esc, bracket.
  677.                TEST    STATUS,XOFF             ;^ Are @Xnn colors off?
  678.                JNZ     FLUSH_END               ;^ Yes, Ignore this completely
  679.                INC     CL                      ;& Is it @XFF restore code?
  680.                JNZ     COLOR_2                 ;& No,  Check for save code
  681.                MOV     CL,SAVE_ATTRIBUTE       ;& Yes, Get back saved attribute
  682.                JMP     SHORT COLOR_3           ;& and set it
  683. COLOR_2:       DEC     CL                      ;& Is it @X00 save code
  684.                JNZ     COLOR_3                 ;& No,  just set it then
  685.                MOV     CL,ATTRIBUTE            ;& Yes, Save the attribute
  686.                MOV     SAVE_ATTRIBUTE,CL       ;&
  687.                JMP     FLUSH_END               ;& and flush it
  688. COLOR_3:       MOV     ATTRIBUTE,CL            ;@ Set Attribute
  689.                JMP     FLUSH_END               ;@ Clear Buffer
  690.  
  691. ;------------------------------------------------;~
  692. POSITION_SUB:  CMP     AL,'@'                  ;~ Is it another @
  693.                JE      FOUND_END               ;~ Yes, so process it
  694.                CMP     AL,'0'                  ;~ No, is it Numeric?
  695.                JB      SHORT_FLUSH2            ;~ No, and invalid!
  696.                CMP     AL,'9'                  ;~ Maybe, let's see
  697.                JA      CHECK_TYPE              ;~ No, maybe a justification
  698.                CALL    ACCUMULATE              ;~ Build the number
  699.                JMP     SHORT BUFFER_IGNORE     ;~
  700. CHECK_TYPE:    MOV     AH,AL                   ;~ Copy it so we can Capitalize
  701.                AND     AH,0DFh                 ;~ Force Upper Case
  702.                CMP     AH,'C'                  ;~ Centered?
  703.                JE      POS_TYPE                ;~ Yes,
  704.                CMP     AH,'R'                  ;~ No, Right Justified?
  705.                JE      POS_TYPE                ;~     Yes,
  706. SHORT_FLUSH2:  MOV     IGNORE,0                ;~ No, So Zero out IGNORE!
  707.                JMP     SHORT_FLUSH             ;~     Invalid character
  708. POS_TYPE:      MOV     JUSTIFY, AH             ;~     Yes, Save the type
  709. BUFFER_IGNORE: INC     IGNORE                  ;~ We have to ignore these
  710. BUFFER_JUMP:   JMP     BUFFER_CHAR             ;~ But buffer the character also
  711.  
  712. ;------------------------------------------------;@
  713. VARIABLE_SUB:  CMP     AL,':'                  ;~ Is it a ':' instead of '@'
  714.                JNE     VARIABLE_2              ;~ No, continue
  715.                MOV     BYTE PTR NUMBER_BUFFER,0;~ Reset Variable
  716.                MOV     JUSTIFY,'L'             ;~ Reset justification to default
  717.                MOV     BX, OFFSET POSITION_SUB ;~ Yes, Redirect the ANSI_STATE
  718.                INC     IGNORE                  ;~ We need to ignore this
  719.                JMP     STORE_STATE             ;~ Store the state
  720. VARIABLE_2:                                    ;~
  721.                CMP     AL,'@'                  ;@ Is it another @
  722.                JE      FOUND_END               ;~ Yes, so process it
  723.                JB      SHORT_FLUSH2            ;@ No, and not valid, so flush
  724.                CMP     AL,'Z'                  ;~ Is it UpperCase
  725.                JA      SHORT_FLUSH2            ;~ No, so flush
  726.                JMP     BUFFER_JUMP           ;&;@ No, Buffer the Char (indirect)
  727. FOUND_END:                                     ;~
  728.                MOV     DX,OFFSET AT_VARIABLE_TABLE ;@ Point to Variable List
  729.                XOR     BX,BX                   ;@ Position in Variable List
  730. NEXT_VARI:     MOV     DI,DX                   ;@ Load DI
  731.                INC     BX                      ;@ Count the Variable
  732.                MOV     SI,OFFSET ESC_BUFFER    ;@ Point to our Variable
  733.                MOV     CX,OFFSET LAST_VARIABLE ;@ Point to End of list
  734.                SUB     CX,DI                   ;@ Minus our current location
  735.                MOV     AL,'@'                  ;@ We need to start on these
  736.                REPNE   SCASB                   ;@ so find one
  737.                JCXZ    SHORT_FLUSH             ;@ End of List? Yes
  738.                MOV     DX,DI                   ;@ No,Save Variable list pointer
  739.                DEC     DI                      ;@ No, Back up to the @
  740.                MOV     CX,ESC_COUNT            ;@ Length of Variable
  741.                SUB     CX,IGNORE               ;~ But ignore the last few maybe
  742.                REP     CMPSB                   ;@ See if this one matches?
  743.                JNZ     NEXT_VARI               ;@ Didn't match that one!
  744.                CMP     [DI],AL                 ;@ Last Character has to be an @
  745.                JNZ     NEXT_VARI               ;@ Nope
  746.                DEC     BX                      ;@ Back up 1
  747.                CMP     BX,ACTION_CODES-1       ;@ Is it an Action code     ;~
  748.                JA      NOT_ACTION              ;@ No
  749.                SHL     BX,1                    ;@ BX x 2 for proper offset
  750.                MOV     DI,OFFSET JUMP_TABLE    ;@ Point to command table
  751.                ADD     DI,BX                   ;@ Adjust to the desired command
  752.                JMP     EXECUTE                 ;@ Execute the command
  753. NOT_ACTION:    MOV     SI, OFFSET SUB_TABLE    ;@ Point to Sub Table
  754.                MOV     AX,BX                   ;@ Save Variable Number
  755.                MOV     CX,BX                   ;@ Copy Variable Number
  756.                XOR     BX,BX                   ;@ Zero Offset
  757.                XOR     DX,DX                   ;@ Zero out initial length
  758.                SUB     CX,ACTION_CODES-1       ;@ Adjust Variable Number   ;~
  759. NEXT_OFFSET:   ADD     BX,DX                   ;@ Add last Length to Offset
  760.                MOV     DL,[SI]                 ;@ Get Length
  761.                INC     SI                      ;@ Bump the pointer
  762.                LOOP    NEXT_OFFSET             ;@ Do all of them
  763.                MOV     CX,DX                   ;@ Get last Length
  764.                MOV     SI,OFFSET SUB_LIST      ;@ Point to the substitue buffer.
  765.                ADD     SI,BX                   ;@ Add Offset
  766.                SUB     AX,STRING_CODES         ;@ Is It a String Variable ;~
  767.                JB      IS_STRING               ;@ Yes, Flush our Substitute
  768.                CMP     AX,1                    ;@ Is it Date ot Time?
  769.                JBE     IS_TIMEDATE             ;@ No, It's a Number
  770.                SUB     AX,2                    ;@ Adjust Variable number
  771.                CALL    NUMBER_PARSE            ;@ Create a Numeric value then
  772.                JMP     SHORT VAR_END           ;@ Flush our Number
  773. IS_TIMEDATE:   CALL    MAKE_TIMEDATE           ;@
  774. IS_STRING:     MOV     DI,SI                   ;@ Copy Pointer to DI for SCASB
  775.                MOV     AL,0                    ;@ We look for a Zero
  776.                REPNE   SCASB                   ;@ Findit it
  777.                JNE     GOT_END                 ;@ Skip if we didn't hit a Zero
  778.                DEC     DI                      ;@ Back up if we did
  779. GOT_END:       MOV     CX,DI                   ;@ Get Current Location
  780.                SUB     CX,SI                   ;@ Subtract Starting Location
  781. VAR_END:       JMP     FLUSH_BUFF3          ;~ ;@ Flush our Substitute
  782.  
  783. SHORT_FLUSH:   PUSH    AX                      ;& Save Character
  784.                CALL    FLUSH_BUFF2             ;@ Flush what we have now
  785.                POP     AX                      ;& Restore Character
  786.                JMP     ESC_STATE               ;& And save the new state
  787.  
  788. ;------------------------------------------------;~
  789. PAD_STRING:    PUSH    CX                      ;~ Save count
  790.                PUSH    SI                      ;~ Save Pointer
  791.                LAHF                            ;~ Save Carry in AH
  792.                CMP     IGNORE,0                ;~ Do we need to pad?
  793.                JE      NO_PAD                  ;~ No, nevermind
  794.                MOV     BL,BYTE PTR NUMBER_BUFFER ;~
  795.                XOR     BH,BH                   ;~ Get the length desired in BX
  796.                CMP     BX,CX                   ;~ Variable Longer?
  797.                JL      NO_PAD                  ;~ Yes, nevermind
  798.                SUB     BX,CX                   ;~ We need this many spaces
  799.                XOR     BH,BH                   ;~ Keep it short
  800.                MOV     CX,BX                   ;~ We need it in CX
  801.                CMP     JUSTIFY,'R'             ;~ Right justification?
  802.                JNE     PAD_2                   ;~ No, Left or Center
  803.                SAHF                            ;~ Yes, Get Carry NC=RIGHT PAD
  804.                JNC     NO_PAD                  ;~ Nevermind, Were not doing it
  805.                JMP     SHORT DO_PAD            ;~ Pad it
  806. PAD_2:         CMP     JUSTIFY,'C'             ;~ Center justification?
  807.                JE      PAD_3                   ;~ Yes,
  808.                SAHF                            ;~ No, Must be Left (Default)
  809.                JC      NO_PAD                  ;~ Nevermind, Were not doing it
  810.                JMP     SHORT DO_PAD            ;~ Pad it
  811. PAD_3:         SHR     CX,1                    ;~ Centering Divide by 2
  812.                SAHF                            ;~ Yes, Get Carry NC=RIGHT PAD
  813.                JNC     DO_PAD                  ;~ OK, we are padding the RIGHT
  814.                SUB     BX,CX                   ;~ OK, we are padding the LEFT
  815.                MOV     CX,BX                   ;~     so use the remainder
  816. DO_PAD:        CALL    POS_IT0                 ;~ So go write the spaces.
  817. NO_PAD:        POP     SI                      ;~ restore pointer
  818.                POP     CX                      ;~ restore count
  819.                RET                             ;~ and back we go.
  820.  
  821. ;------------------------------------------------;@
  822. ATX_STATE:     MOV     BX,OFFSET COLOR_STATE   ;@ Assume 'X' Character
  823.                CMP     AL,'X'                  ;@ Is it X? If yes, store
  824.                JZ      SHORT_STORE             ;@ char. and next state.
  825.                CMP     AL,'@'                  ;@ Is it another '@' already?
  826.                JZ      WRITE_CHAR              ;@ Yes!
  827.                CMP     AL,ESC_CHAR             ;& Is it an Escape
  828.                JE      SHORT_FLUSH             ;& Yes, so flush buffer & restart
  829.                MOV     BX,OFFSET VARIABLE_SUB  ;@ No, Must be a Variable
  830.                MOV     IGNORE,0                ;~ Reset IGNORE Count to Zero
  831. SHORT_STORE:   JMP     STORE_STATE             ;@ Store the state
  832. endif                                             ;$
  833. ;------------------------------------------------;
  834. ; Slow video writes are via BIOS Write TTY.      ;
  835. ;------------------------------------------------;
  836.  
  837. WRITE_CHAR:    CMP     AL,BELL                 ;Let BIOS process BS and BELL.
  838.                JZ      WRITE_TTY
  839.                CMP     AL,BS
  840.                JZ      WRITE_TTY
  841.  
  842.                CALL    GET_BIOS_DATA           ;Get BIOS video data.
  843.                CMP     AL,TAB                  ;Is character a TAB?
  844.                JNZ     CK_ACTIVE               ;If no, process normally.
  845.                MOV     CX,CURSOR_POSN          ;Else, expand TAB to
  846.                AND     CX,7                    ; appropriate space characters.
  847.                NEG     CX
  848.                ADD     CX,8
  849. NEXT_TAB:      PUSH    CX
  850.                MOV     AL,SPACE
  851.                CALL    CK_ACTIVE
  852.                POP     CX
  853.                LOOP    NEXT_TAB
  854.                RET
  855.  
  856. CK_ACTIVE:     TEST    STATUS,OFF              ;Is ANSI OFF?
  857.                JNZ     WRITE_TTY               ;If yes, write via BIOS TTY.
  858. CK_FAST:       CALL    CK_SLOW_TEXT            ;Is ANSI SLOW or in graphics
  859.                JNC     WRITE_FAST              ; mode? If no, write fast.
  860.  
  861.                CMP     AL,CR                   ;Let BIOS handle CR and LF.
  862.                JZ      WRITE_TTY
  863.                CMP     AL,LF
  864.                JZ      WRITE_TTY
  865.  
  866. WRITE_SLOW:    PUSH    AX                      ;Else, write character/attribute
  867.                MOV     CX,1                    ; at current cursor position
  868.                MOV     BH,ACTIVE_PAGE          ; via BIOS.
  869.                MOV     BL,ATTRIBUTE
  870.                MOV     AH,9
  871.                INT     10H
  872.                POP     AX
  873.  
  874.                CMP     LINE_WRAP,ON            ;Is line wrap on?
  875.                JZ      TTY                     ;If yes, continue.
  876.                MOV     CX,CRT_COLS             ;Else, cursor at rightmost
  877.                DEC     CL                      ; column?
  878.                CMP     CL,CURSOR_COL           ;If yes, continue, else
  879.                JNZ     TTY                     ; return without writing.
  880.                RET
  881.  
  882. ;------------------------------------------------;
  883.  
  884. WRITE_TTY:     MOV     BL,7                    ;Attribute in graphics mode.
  885. TTY:           MOV     AH,0EH
  886.                INT     10H
  887.                RET
  888.  
  889. ;----------------------------------------------------------------------------;
  890. ; Fast screen writes are directly to the video buffer without retrace check. ;
  891. ;----------------------------------------------------------------------------;
  892.  
  893. WRITE_FAST:    PUSH    ES                      ;Preserve extra segment.
  894.                MOV     DX,CURSOR_POSN          ;Retrieve cursor position.
  895.                CMP     AL,CR                   ;Carriage return?
  896.                JNZ     CK_LINEFEED             ;If no, check linefeed.
  897.                XOR     DL,DL                   ;Else, cursor to first column.
  898.                JMP     SHORT UPDATE_CURSOR
  899. CK_LINEFEED:   CALL    VIDEO_SETUP             ;Calculate video address.
  900.                CMP     AL,LF                   ;Linefeed?
  901.                JZ      NEXT_ROW                ;If yes, next row.
  902.  
  903.                MOV     AH,ATTRIBUTE            ;Retrieve attribute.
  904.                STOSW                           ;Put char/attrib in video buffer.
  905.                INC     DL                      ;Increment cursor column.
  906.                CMP     DL,BYTE PTR CRT_COLS    ;End of row?
  907.                JB      UPDATE_CURSOR           ;If no, update cursor.
  908.  
  909.                CMP     LINE_WRAP,OFF           ;Else, line wrap off?
  910.                JZ      FAST_END                ;If yes, don't move cursor.
  911.                XOR     DL,DL                   ;Else, column zero.
  912. NEXT_ROW:      INC     DH                      ;Next row.
  913.                CALL    INFORMATION             ;Get displayable row info.
  914.                CMP     DH,AL                   ;Beyond the bottom of screen?
  915.                JBE     UPDATE_CURSOR           ;If no, update cursor.
  916.  
  917.                DEC     DH                      ;Else, cursor to original row.
  918.                MOV     AX,CRT_COLS             ;. Get number of columns
  919.                PUSH    DX                      ;. Save Cursor position
  920.                PUSH    AX                      ;. Save Columns
  921.                SHL     AX,1                    ;. Twice for Char/Attribute
  922.                MOV     SI,AX                   ;. Starting offset in SI
  923.                MOV     DL,START_SCROLL         ;. Where we allow scroll to start
  924.                MUL     DL                      ;. Calculate offset in AX
  925.                SUB     DH,DL                   ;. Reduce line count
  926.                MOV     DI,CRT_START            ;Point destination to top.
  927.                ADD     DI,AX                   ;. Add offset
  928.                ADD     SI,DI                   ;. Point source to second row
  929.                POP     AX                      ;. Get Back Columns
  930.                PUSH    AX                      ;. Save it again
  931.                MUL     DH                      ;Times displayable rows - 1.
  932.                MOV     CX,AX                   ; equals char/attrib to scroll.
  933.                PUSH    DS                      ;Save data segment and
  934.                PUSH    ES                      ; point to video segment.
  935.                POP     DS
  936.                REP     MOVSW                   ;Scroll the screen.
  937.                POP     DS                      ;Restore data segment.
  938.                POP     CX                      ;Retrieve CRT columns.
  939.                POP     DX                      ;.Get back Cursor info
  940.                MOV     AL,SPACE                ;Write space/attrib to
  941.                MOV     AH,ATTRIBUTE            ; bottom row.
  942.                REP     STOSW
  943.  
  944. UPDATE_CURSOR: CALL    SET_CURSOR              ;Update the cursor position.
  945. FAST_END:      POP     ES                      ;Restore extra segment.
  946.                RET
  947. if PCB                                            ;$
  948. ;@************ SUPPORT ROUTINES *************;
  949.  
  950. QOFF:          MOV     AL,0FFH                 ;& Show QOFF
  951.                JMP     SHORT QON2              ;&
  952. QON:           XOR     AL,AL                   ;& Show QON
  953. QON2:          MOV     Q_STATE,AL              ;& Store the state
  954.                RET                             ;& All done
  955.  
  956. BEEP:          MOV     AL,7                    ;@
  957.                JMP     WRITE_CHAR              ;@
  958. MORE:          MOV     AX,MORE_DELAY           ;@
  959.                JMP     SHORT PAUSE2            ;@
  960. PAUSE:         MOV     AX,PAUSE_DELAY          ;@
  961. PAUSE2:        CMP     Q_STATE,0               ;& Are we at a QOFF state
  962.                JNZ     WAIT1                   ;& Yes, then these are WAITs
  963.                MOV     SI,OFFSET MORE_PROMPT   ;@ Point to More? Prompt
  964.                MOV     CX,MORE_LENGTH          ;@ Get the Length of it
  965.                JMP     SHORT WAIT2             ;@ Go Wait
  966. WAIT1:         MOV     AX,WAIT_DELAY           ;@
  967.                MOV     SI,OFFSET WAIT_PROMPT   ;@ Point to Wait Prompt
  968.                MOV     CX,WAIT_LENGTH          ;@ Get the Length of it
  969. WAIT2:         MOV     PAUSE_TIMER,AX          ;@
  970. ;               PUSH    CX                      ;@ Save Length
  971. WAIT2_LOOP:    LODSB                           ;@ Get Character
  972.                PUSH    CX                      ;@
  973.                PUSH    SI                      ;@
  974.                CALL    WRITE_CHAR              ;@ Output it
  975.                POP     SI                      ;@
  976.                POP     CX                      ;@
  977.                LOOP    WAIT2_LOOP              ;@ Do all the Characters
  978. WAIT_LOOP:     MOV     AH,1                    ;@ KeyBoard Status
  979.                INT     16H                     ;@ Keyboard I/O Services
  980.                JNZ     CONTINUE                ;@ Key Hit!
  981.                CMP     PAUSE_TIMER,0           ;@ Timer Run out?
  982.                JNE     WAIT_LOOP               ;@ No
  983.                JMP     SHORT WAIT3             ;@ Yes
  984. CONTINUE:      MOV     AH,0                    ;@ KeyBoard Read
  985.                INT     16H                     ;@ Keyboard I/O Services
  986. WAIT3:                                         ;@
  987.                XOR     CL,CL                   ;@ Clear the Attribute
  988.                XCHG    CL,ATTRIBUTE            ;&  and
  989.                PUSH    CX                      ;&    save it too
  990.                MOV     DX,CURSOR_POSN          ;& Get Cursor
  991.                MOV     DL,0                    ;& First column
  992.                CALL    SET_CURSOR              ;& Set the new Cursor
  993.                CALL    ERASE_2                 ;& Erase the line
  994. ;&
  995. ;& The following lines (and the PUSH CX above) will clear only the PROMPT
  996. ;& and leave the cursor where it was when the prompt appears. This was
  997. ;& different than PCBoard 14.5 so I changed it to clear the entire line
  998. ;& via the above four lines. Left the old code in case someome wanted it.
  999. ;&
  1000. ;&               POP     CX                      ;@ Get back Length
  1001. ;&ERASE_LOOP:    PUSH    CX                      ;@ Save it again
  1002. ;&               MOV     AL,BS                   ;@ Send BS
  1003. ;&               CALL    WRITE_CHAR              ;@  character
  1004. ;&               MOV     AL,' '                  ;@  and then space
  1005. ;&               CALL    WRITE_CHAR              ;@  character to erase
  1006. ;&               MOV     AL,BS                   ;@  then BS again
  1007. ;&               CALL    WRITE_CHAR              ;@  to backup.
  1008. ;&               POP     CX                      ;@ get back length again
  1009. ;&               LOOP    ERASE_LOOP              ;@ Erase entire prompt.
  1010.                POP     CX                      ;& Restore
  1011.                MOV     ATTRIBUTE,CL            ;&  the Attribute
  1012.                RET                             ;@
  1013. AUTOOFF:       MOV     AX,WAIT_DELAY           ;@ Restore More to a Wait
  1014.                JMP     SHORT AUTO2             ;@
  1015. AUTOMORE:      MOV     AX,PAUSE_DELAY          ;@ Make More a Pause
  1016. AUTO2:         MOV     MORE_DELAY,AX           ;@
  1017. SKIP_IT:       RET                             ;@
  1018. DELAY_IT:      PUSH    DX                      ;~ Save registers
  1019.                PUSH    BX                      ;~
  1020.                MOV     AX,182                  ;~ Multiply number by 182
  1021.                MOV     BX,10                   ;~ Then divide by 10
  1022.                XOR     DX,DX                   ;~ Prepare for division
  1023.                MUL     BYTE PTR NUMBER_BUFFER  ;~
  1024.                DIV     BX                      ;~
  1025.                MOV     PAUSE_TIMER,AX          ;~ This should be Num * 18.2
  1026.                POP     BX                      ;~ Restore registers
  1027.                POP     DX                      ;~
  1028.                JMP     WAIT_LOOP               ;~ Now do the delay
  1029. POS_IT:        MOV     AL,BYTE PTR NUMBER_BUFFER ;~
  1030.                MOV     DX,CURSOR_POSN          ;~ Get Cursor
  1031.                INC     DL                      ;~ Adjust for ordinal
  1032.                SUB     AL,DL                   ;~ Are we beyond it already?
  1033.                JLE     POS_IT2                 ;~ Yes, nevermind
  1034.                MOV     CL,AL                   ;~ No, Put loop count in CX
  1035.                XOR     CH,CH                   ;~
  1036. POS_IT0:       MOV     AL,' '                  ;~ Write Spaces
  1037. POS_IT1:       PUSH    CX                      ;~ Save the count
  1038.                CALL    WRITE_CHAR              ;~
  1039.                POP     CX                      ;~ Restore the count
  1040.                LOOP    POS_IT1                 ;~ Until Done
  1041. POS_IT2:       RET                             ;~
  1042.  
  1043. endif                                             ;$
  1044. ;************* SUPPORT ROUTINES *************;
  1045.  
  1046. CK_QUOTE:      MOV     BX,OFFSET QUOTE_STATE   ;Assume quote state.
  1047.                MOV     AH,DOUBLE_QUOTE
  1048.                CMP     AL,AH                   ;Is it double quote?
  1049.                JZ      GOT_QUOTE               ;If yes, string delimiter.
  1050.                MOV     AH,SINGLE_QUOTE         ;Is it single quote?
  1051.                CMP     AL,AH                   ;Is yes, string delimiter.
  1052.                JNZ     QUOTE_END               ;Else, return ZR = 0.
  1053. GOT_QUOTE:     MOV     QUOTE_TYPE,AH           ;Store as matching string end.
  1054. QUOTE_END:     RET
  1055.  
  1056. ;------------------------------------------------;
  1057.  
  1058. ACCUMULATE:    PUSH    AX                      ;Preserve number character.
  1059.                SUB     AL,'0'                  ;Convert ASCII to binary.
  1060.                MOV     CL,AL                   ;Save the number.
  1061.                MOV     AX,10                   ;Multiply previous count by 10.
  1062.                MOV     BX,NUMBER_COUNT
  1063.                MUL     BYTE PTR NUMBER_BUFFER[BX]
  1064.                ADD     AL,CL                            ;Add in new number
  1065.                MOV     BYTE PTR NUMBER_BUFFER[BX],AL    ; and store.
  1066.                POP     AX
  1067.                RET
  1068. if PCB                                            ;$
  1069. ;------------------------------------------------;@
  1070.  
  1071. ACCUM_COLOR:   PUSH    AX                      ;@ Preserve number character.
  1072.                SUB     AL,'0'                  ;@ Convert ASCII to hex
  1073.                MOV     AH,BYTE PTR NUMBER_BUFFER ;@ Get current number
  1074.                SHL     AH,1                      ;@ Shift left 4 bits
  1075.                SHL     AH,1                      ;@
  1076.                SHL     AH,1                      ;@
  1077.                SHL     AH,1                      ;@
  1078.                OR      AH,AL                     ;@ Add in new number
  1079.                MOV     BYTE PTR NUMBER_BUFFER,AH ;@ and store.
  1080.                MOV     CL,AH                     ;@ Return with Color in CL
  1081.                POP     AX                        ;@
  1082.                RET                               ;@
  1083.  
  1084. NUMBER_PARSE:  MOV  BX,[SI]                 ;@ Get low word
  1085.                MOV  DX,AX                   ;@ Save Variable Number
  1086.                XOR  AX,AX                   ;@ Assume Integer
  1087.                CMP  CX,4                    ;@ Is that a Long Integer?
  1088.                JNE  SHORT_INT               ;@ No, Integer
  1089.                MOV  AX,[SI + 2]             ;@ Yes, Get high word
  1090. SHORT_INT:     MOV  DI, OFFSET PARSE_BUFFER ;@ Point DI at number space
  1091.                MOV  CX,10                   ;@ Set divisor to 10
  1092.                XOR  SI,SI                   ;@ Clear SI as counter
  1093.                MOV  COMMA,2                 ;@ Assume a Ratio
  1094.                CMP  DX,2                    ;@ Is it a Ratio?
  1095.                JB   GETDIGIT                ;@ No
  1096. RESET_COMMA:   MOV  COMMA,4                 ;@ Set Comma Counter
  1097. GETDIGIT:      DEC  DI                      ;@ Point DI at correct character
  1098.                INC  SI                      ;@ Register that we have a character
  1099.                DEC  COMMA                   ;@ Do we need a Comma?
  1100.                JNZ  NO_COMMA                ;@ No
  1101.                MOV  BYTE PTR [DI],','       ;@ Yes, So Put one in!
  1102.                JMP  RESET_COMMA             ;@ And restart the Comma count.
  1103. NO_COMMA:      XOR  DX,DX                   ;@ Clear DX to take remainder
  1104.                DIV  CX                      ;@ Divide AX first (High word)
  1105.                MOV  BP,AX                   ;@ Save quotient
  1106.                MOV  AX,BX                   ;@ Get low word
  1107.                DIV  CX                      ;@ DX had leftover from first divide
  1108.                MOV  BX,AX                   ;@ Save quotient
  1109.                MOV  AX,BP                   ;@ Put high word back
  1110.                ADD  DL,30h                  ;@ Make it an ASCII digit from remainder
  1111.                MOV  [DI],DL                 ;@ Put it in our string
  1112.                OR   AX,AX                   ;@ Is high word zero?
  1113.                JNZ  GETDIGIT                ;@ No keep going
  1114.                OR   BX,BX                   ;@ Is low word zero?
  1115.                JNZ  GETDIGIT                ;@ No keep going
  1116.                MOV  CX,SI                   ;@ Digit count to CX
  1117.                MOV  SI,DI                   ;@ String Pointer to SI
  1118.                MOV  DI, OFFSET PARSE_BUFFER ;@ Point DI at number space
  1119.                CMP  BYTE PTR [DI][-2],','   ;@ Was it a Ratio
  1120.                JNE  NOT_RATIO               ;@ No, nevermind
  1121.                MOV  BYTE PTR [DI][-2],'.'   ;@ Change comma to Decimal
  1122.                MOV  BYTE PTR [DI],':'       ;@ Yes, Add ':1' to it
  1123.                MOV  BYTE PTR [DI][1],'1'    ;@
  1124.                ADD  CX,2                    ;@ Account for two more characers
  1125. NOT_RATIO:     RET                          ;@
  1126.  
  1127. MAKE_TIMEDATE: MOV  DI, OFFSET NUMBER_BUFFER ;@ Point to Number Buffer
  1128.                MOV  SI,DI            ;@ Save it in SI too
  1129.                JE   MAKE_TIME        ;@ It was TIME on Entry!
  1130.                MOV  CX,8             ;@ It was DATE! Length = 8
  1131.                PUSH CX               ;@ Save Length
  1132.                MOV  AH,04H           ;@ Get date service
  1133.                INT  1AH              ;@ Call BIOS - return codes as follows:
  1134.                PUSH CX               ;@ CH = Century (19-20)  CL = Year (00-99)
  1135.                PUSH DX               ;@ DH = Month   (1-12)   DL = Day  (00-31)
  1136.                MOV  AL,DH            ;@ Month
  1137.                CALL ASCII            ;@ Convert byte to ASCII digits
  1138.                MOV  AL,'-'           ;@
  1139.                STOSB                 ;@
  1140.                POP  AX               ;@ Day - was DX when pushed
  1141.                CALL ASCII            ;@ Convert byte to ASCII digits
  1142.                MOV  AL,'-'           ;@
  1143.                STOSB                 ;@
  1144.                POP  AX               ;@ Year - was CX when pushed
  1145.                POP  CX               ;@ Restore Length
  1146.                JMP  SHORT ASCII      ;@ Convert byte to ASCII digit
  1147.  
  1148. MAKE_TIME:     MOV  CX,5             ;@ Length = 5
  1149.                PUSH CX               ;@ Save Length
  1150.                MOV  AH,02H           ;@ Get time service
  1151.                INT  1AH              ;@ Call BIOS - return codes as follows:
  1152.                PUSH CX               ;@ CH = Hours   (0-23)   CL = Minutes (0-59)
  1153.                MOV  AL,CH            ;@ Hours
  1154.                CALL ASCII            ;@ Convert byte to ASCII digits
  1155.                MOV  AL,':'           ;@
  1156.                STOSB                 ;@
  1157.                POP  AX               ;@ Minutes - was CX when pushed
  1158.                POP  CX               ;@ Restore Length
  1159. ASCII:         MOV  AH,AL            ;@ Need to get BCD Digits
  1160.                SHR  AL,1             ;@  MSD in AL
  1161.                SHR  AL,1             ;@   lower
  1162.                SHR  AL,1             ;@     4
  1163.                SHR  AL,1             ;@     Bits
  1164.                AND  AH,0FH           ;@ And LSD in AH cleanly
  1165.                OR   AX,3030H         ;@ Convert to ASCII
  1166.                STOSW                 ;@ Stuff Digits into Buffer (in reverse)
  1167.                RET                   ;@ SI Points to String Data
  1168. endif                                   ;$
  1169. ;---------------------------------------------------------------------------;
  1170. ; OUTPUT:  CY = 1 if write SLOW mode or in graphics mode; CY = 0 otherwise. ;
  1171. ;---------------------------------------------------------------------------;
  1172.  
  1173. CK_SLOW_TEXT:  TEST    STATUS,SLOW
  1174.                JNZ     SLOW_MODE
  1175.                CMP     CRT_MODE,7
  1176.                JZ      TEXT_MODE
  1177.                CMP     CRT_MODE,3
  1178.                JA      SLOW_MODE
  1179. TEXT_MODE:     CLC
  1180.                RET
  1181.  
  1182. SLOW_MODE:     STC
  1183.                RET
  1184.  
  1185. ;-------------------------------------;
  1186. ; OUTPUT:  AL = Screen rows minus one ;
  1187. ;-------------------------------------;
  1188.  
  1189. INFORMATION:   PUSH    DS                      ;Save data segment.
  1190.                MOV     AX,40H                  ;Point to BIOS data.
  1191.                MOV     DS,AX
  1192.                MOV     AL,DS:[84H]             ;Retrieve rows - 1.
  1193.                OR      AL,AL                   ;BIOS supported?
  1194.                JNZ     INFO_END                ;If yes, done here.
  1195.                MOV     AL,24                   ;Else, assume 25 lines.
  1196. INFO_END:      POP     DS
  1197.                RET
  1198.  
  1199. ;------------------------------------------------------------------------------;
  1200. ; INPUT:  DX = Cursor position.                                                ;
  1201. ; OUTPUT: ES = Video buffer segment; DI = Video buffer offset; AX,DX preserved ;
  1202. ;------------------------------------------------------------------------------;
  1203.  
  1204. VIDEO_SETUP:   PUSH    AX
  1205.                MOV     AX,CRT_COLS             ;Retrieve CRT columns.
  1206.                MUL     DH                      ;Times cursor row.
  1207.                MOV     BL,DL
  1208.                XOR     BH,BH
  1209.                ADD     AX,BX                   ;Plus cursor column.
  1210.                SHL     AX,1                    ;Times two for attribute.
  1211.                MOV     DI,CRT_START            ;Plus starting video offset.
  1212.                ADD     DI,AX                   ;Equals destination.
  1213.  
  1214.                MOV     BX,0B000H               ;Assume mono card.
  1215.                CMP     ADDR_6845,3B4H          ;Is it mono port?
  1216.                JZ      VIDEO_SEGMENT           ;If yes, guessed right.
  1217.                ADD     BX,800H                 ;Else, point to color segment.
  1218. VIDEO_SEGMENT: MOV     ES,BX
  1219.                POP     AX
  1220.                RET
  1221.  
  1222. ;------------------------------------------------;
  1223. ; Move BIOS video data into our data segment.    ;
  1224. ;------------------------------------------------;
  1225.  
  1226. GET_BIOS_DATA: PUSH    DS
  1227.                PUSH    DI                      ;Point to BIOS data segment.
  1228.                MOV     BX,40H
  1229.                MOV     DS,BX
  1230.                MOV     SI,BIOS_ACTIVE_PAGE     ;Start with active page.
  1231.                MOV     DI,OFFSET ACTIVE_PAGE
  1232.                MOVSB                           ;Retrieve active page
  1233.                MOVSW                           ; and address of 6845 port.
  1234.                MOV     SI,BIOS_CRT_MODE        ;Retrieve CRT mode, CRT columns,
  1235.                MOV     CX,CRT_DATA_LENGTH      ; CRT length, CRT start.
  1236.                REP     MOVSB
  1237.                MOV     BL,ES:ACTIVE_PAGE       ;Use active page as index
  1238.                XOR     BH,BH                   ; of active cursor position.
  1239.                SHL     BX,1
  1240.                ADD     SI,BX
  1241.                MOVSW
  1242.                POP     DI
  1243.                POP     DS
  1244.                RET
  1245.  
  1246. ;----------------------------------------------------------------------------;
  1247. ; OUTPUT: BL = First parameter; BH = Second parameter; DX = cursor position. ;
  1248. ;----------------------------------------------------------------------------;
  1249.  
  1250. ADJUST_NUMBER: MOV     BX,WORD PTR NUMBER_BUFFER
  1251.                OR      BH,BH
  1252.                JNZ     ADJUST_AL               ;If either parameter zero,
  1253.                INC     BH                      ; increment to convert
  1254. ADJUST_AL:     OR      BL,BL                   ; to base one.
  1255.                JNZ     ADJUST_END
  1256.                INC     BL
  1257. ADJUST_END:    MOV     DX,CURSOR_POSN          ;Return cursor position.
  1258.                RET
  1259.  
  1260. ;--------------------------------------------------------------------------;
  1261. ; INPUT:  AX = number; BP = 0 if console output; BP = 1 if storage output. ;
  1262. ;--------------------------------------------------------------------------;
  1263.  
  1264. DECIMAL_OUT:   MOV     BX,10                   ;Divisor of ten.
  1265.                XOR     CX,CX                   ;Zero in counter.
  1266. NEXT_COUNT:    XOR     DX,DX                   ;Zero in high half.
  1267.                DIV     BX                      ;Divide by ten.
  1268.                ADD     DL,'0'                  ;Convert to ASCII.
  1269.                PUSH    DX                      ;Save results.
  1270.                INC     CX                      ;Also increment count.
  1271.                CMP     AX,0                    ;Are we done?
  1272.                JNZ     NEXT_COUNT              ;Continue until zero.
  1273.                OR      BP,BP                   ;If BP zero, output to screen.
  1274.                JNZ     DEVICE_OUTPUT           ;Else, store in buffer.
  1275.  
  1276. REPORT_OUTPUT: POP     AX                      ;Retrieve number.
  1277.                CALL    PRINT_CHAR              ;Display it.
  1278.                LOOP    REPORT_OUTPUT
  1279.                RET
  1280.  
  1281. DEVICE_OUTPUT: CMP     CX,2                    ;Two digits?
  1282.                JZ      TWO_DIGITS              ;If yes, process normally.
  1283.                MOV     AL,'0'                  ;Else, store leading zero.
  1284.                STOSB
  1285.  
  1286. TWO_DIGITS:    POP     AX                      ;Retrieve number.
  1287.                STOSB                           ;Store it
  1288.                LOOP    TWO_DIGITS
  1289.                RET
  1290.  
  1291. ;************* ANSI COMMAND SUBSET *************;
  1292.  
  1293. CLS:           MOV     BH,7                    ;Assume normal attribute.
  1294.                MOV     BL,BYTE PTR CRT_MODE    ;Get current video mode.
  1295.                CMP     BL,4
  1296.                JBE     CK_CLS_STATUS           ;If text mode then check if
  1297.                CMP     BL,7                    ; ANSI active.
  1298.                JZ      CK_CLS_STATUS
  1299.                XOR     BH,BH                   ;Else, use black attribute
  1300.                TEST    STATUS,OFF
  1301.                JNZ     CLS_SLOW                ;If ANSI inactive, via BIOS.
  1302.                JMP     SHORT CK_CLS_SLOW       ;Else, check if FAST or SLOW.
  1303.  
  1304. CK_CLS_STATUS: TEST    STATUS,OFF              ;Is ANSI OFF?
  1305.                JNZ     CLS_SLOW                ;If yes, CLS via BIOS.
  1306.                MOV     BH,ATTRIBUTE            ;Else, current attribute.
  1307. CK_CLS_SLOW:   CALL    CK_SLOW_TEXT
  1308.                JC      CLS_SLOW                ;If ANSI SLOW, via BIOS.
  1309.  
  1310. CLS_FAST:      MOV     AH,BH                   ;Else, attribute in high half.
  1311.                MOV     AL,SPACE                ;Space character in low half.
  1312.                XOR     DX,DX                   ;Cursor position home.
  1313.                MOV     DH,START_SCROLL         ;$ protect lines
  1314.                CALL    VIDEO_SETUP             ;Calculate video address.
  1315.                MOV     CX,CRT_LEN              ;Retrieve CRT length.
  1316.                SHR     CX,1                    ;Times two for attribute.
  1317.                REP     STOSW                   ;Write directly to video buffer.
  1318.                JMP     SHORT SET_CURSOR        ;Set the cursor top left corner.
  1319.  
  1320. CLS_SLOW:      CALL    INFORMATION             ;Get displayable rows.
  1321.                MOV     DH,AL                   ;Store in DH.
  1322.                MOV     DL,BYTE PTR CRT_COLS    ;Retrieve CRT columns.
  1323.                DEC     DL                      ;Adjust to zero base.
  1324.                XOR     CX,CX                   ;Scroll active page.
  1325.                MOV     AX,600H
  1326.                INT     10H
  1327.                XOR     DX,DX                   ;Home the cursor.
  1328.                JMP     SHORT SET_CURSOR
  1329.  
  1330. ;------------------------------------------------;
  1331. CURS_POSITION:                                 ;These two commands are the same.
  1332. HORZ_VERT_POS: CALL    INFORMATION             ;Returns AL = screen rows.
  1333.                CALL    ADJUST_NUMBER           ;Returns BL,BH = parameters.
  1334.                SUB     BX,101H                 ;Zero based.
  1335.                CMP     BL,AL                   ;If cursor request within
  1336. ;$             JA      CURSOR_END              ; boundaries of screen, set it.
  1337.                JBE     ROWOK                   ;$boundaries of screen, set it.
  1338.                MOV     BL,AL                   ;$Set to last row
  1339. ROWOK:         CMP     BH,BYTE PTR CRT_COLS    ;$
  1340. ;$             JAE     CURSOR_END
  1341.                JB      COLOK                   ;$
  1342.                MOV     BH,BYTE PTR CRT_COLS    ;$Set to
  1343.                DEC     BH                      ;$       last column
  1344. COLOK:         XCHG    BH,BL                   ;
  1345.                MOV     DX,BX
  1346.  
  1347. SET_CURSOR:    MOV     BH,ACTIVE_PAGE          ;Set cursor via BIOS.
  1348.                MOV     AH,2
  1349.                INT     10H
  1350. CURSOR_END:    RET
  1351.  
  1352. ;------------------------------------------------;
  1353.  
  1354. CURSOR_UP:     CALL    ADJUST_NUMBER           ;Move cursor up one or more rows
  1355.                OR      DH,DH                   ; without changing column.
  1356.                JZ      CURSOR_END              ;If already at top, ignore.
  1357.                SUB     DH,BL
  1358.                JNC     SET_CURSOR              ;Stay in bounds.
  1359.                XOR     DH,DH
  1360.                JMP     SHORT SET_CURSOR
  1361.  
  1362. ;------------------------------------------------;
  1363.  
  1364. CURSOR_DOWN:   CALL    INFORMATION             ;Returns AL = screen rows.
  1365.                CALL    ADJUST_NUMBER           ;Returns BL,BH =nos.; DX = cursor
  1366.                CMP     DH,AL                   ;Move cursor down requested
  1367.                JZ      CURSOR_END              ; rows without changing column.
  1368.                ADD     DH,BL
  1369.                CMP     DH,AL
  1370.                JNA     SET_CURSOR
  1371.                MOV     DH,AL                   ;Stay in bounds.
  1372.                JMP     SHORT SET_CURSOR
  1373.  
  1374. ;------------------------------------------------;
  1375.  
  1376. CURS_FORWARD:  CALL    ADJUST_NUMBER           ;Returns BL,BH =nos.; DX = cursor
  1377.                MOV     BH,BYTE PTR CRT_COLS    ;Retrieve displayable columns.
  1378.                DEC     BH                      ;Adjust to zero base.
  1379.                CMP     DL,BH                   ;Move cursor forward one or more
  1380.                JZ      CURSOR_END              ; columns without changing row.
  1381.                ADD     DL,BL
  1382.                CMP     DL,BH
  1383.                JNA     SET_CURSOR
  1384.                MOV     DL,BH                   ;Stay in bounds.
  1385.                JMP     SHORT SET_CURSOR
  1386.  
  1387. ;------------------------------------------------;
  1388.  
  1389. CURS_BACKWARD: CALL    ADJUST_NUMBER           ;Returns BL,BH =nos.; DX = cursor
  1390.                OR      DL,DL                   ;Move cursor backward one or
  1391.                JZ      CURSOR_END              ; more columns without changing
  1392.                SUB     DL,BL                   ; row.  Ignore if already left.
  1393.                JNC     SET_CURSOR
  1394.                XOR     DL,DL                   ;Stay in bounds.
  1395.                JMP     SHORT SET_CURSOR
  1396.  
  1397. ;--------------------------------------------------------;
  1398. ; Report cursor position via console; Format: ESC[#;#R   ;
  1399. ;--------------------------------------------------------;
  1400.  
  1401. DEVICE_STATUS: MOV     DI,OFFSET DEVICE_STATUS_BUFFER
  1402.                MOV     AL,ESC_CHAR
  1403.                STOSB                           ;Store leading Esc, bracket
  1404.                MOV     AL,'['                  ;in special Device Status Buffer.
  1405.                STOSB
  1406.  
  1407.                MOV     AL,CURSOR_ROW           ;Retrieve cursor row.
  1408.                XOR     AH,AH                   ;Zero in high half.
  1409.                INC     AX                      ;Convert to base one.
  1410.                MOV     BP,1                    ;Flag as storage.
  1411.                CALL    DECIMAL_OUT             ;Convert to ASCII.
  1412.                MOV     AL,';'                  ;Store delimiting semi-colon.
  1413.                STOSB
  1414.                MOV     AL,CURSOR_COL           ;Do same with cursor column.
  1415.                XOR     AH,AH
  1416.                INC     AX
  1417.                CALL    DECIMAL_OUT
  1418.                MOV     AL,'R'                  ;Add command character
  1419.                STOSB
  1420.                MOV     AL,CR                   ; and carriage return.
  1421.                STOSB
  1422.                SUB     DI,OFFSET DEVICE_STATUS_BUFFER   ;Setup for console out.
  1423.                MOV     REASSIGN_COUNT,DI
  1424.                MOV     REASSIGN_POS,OFFSET DEVICE_STATUS_BUFFER
  1425.                MOV     REASSIGN_FLAG,ON
  1426.                MOV     REMOVE_FLAG,OFF
  1427.                RET
  1428.  
  1429. ;------------------------------------------------;
  1430.  
  1431. SAVE_CURSOR:   MOV     DX,CURSOR_POSN
  1432.                MOV     SAVE_POSITION,DX
  1433.                RET
  1434.  
  1435. ;------------------------------------------------;
  1436.  
  1437. RESTORE_CURS:  MOV     DX,SAVE_POSITION
  1438.                JMP     SET_CURSOR
  1439.  
  1440. ;------------------------------------------------;
  1441.  
  1442. ERASE_IN_LINE: MOV     DX,CURSOR_POSN          ;Erase from the cursor to
  1443. ERASE_2:       MOV     CX,CRT_COLS             ;& the end of the line, including
  1444.                SUB     CL,DL                   ; the current cursor position.
  1445.                CALL    CK_SLOW_TEXT
  1446.                JC      ERASE_SLOW              ;If ANSI ON and not graphics,
  1447.                CALL    VIDEO_SETUP             ; write directly to video buffer
  1448.                MOV     AL,SPACE                ; with space/attribute.
  1449.                MOV     AH,ATTRIBUTE
  1450.                REP     STOSW
  1451.                RET
  1452.  
  1453. ERASE_SLOW:    MOV     CX,DX                   ;Else, erase SLOW via
  1454.                MOV     DL,BYTE PTR CRT_COLS    ; BIOS scroll active page.
  1455.                DEC     DL
  1456.                MOV     BH,ATTRIBUTE
  1457.                MOV     AX,601H
  1458.                INT     10H
  1459.                RET
  1460.  
  1461. ;------------------------------------------------;
  1462. ;            Set Graphics Rendition              ;
  1463. ;------------------------------------------------;
  1464.  
  1465. SGR:           MOV     SI,OFFSET NUMBER_BUFFER     ;Point to number parameters.
  1466. NEXT_SGR:      LODSB                               ;Retrieve parameter.
  1467.                MOV     DI,OFFSET ATTRIBUTE_TABLE   ;Look up attribute in
  1468.                MOV     CX,ATTRIBUTE_LENGTH         ; translation table.
  1469.                REPNZ   SCASB
  1470.                JNZ     SGR_LOOP
  1471.  
  1472.                MOV     DI,OFFSET ATTRIBUTE_END
  1473.                SHL     CX,1
  1474.                SUB     DI,CX
  1475.                MOV     AX,[DI]
  1476.                AND     ATTRIBUTE,AL            ;If match, AND with strip mask.
  1477.                OR      ATTRIBUTE,AH            ;OR with add mask.
  1478. SGR_LOOP:      DEC     NUMBER_COUNT            ;Do all parameters.
  1479.                JNZ     NEXT_SGR
  1480.                RET
  1481.  
  1482. ;------------------------------------------------;
  1483.  
  1484. SET_MODE:      MOV     AH,ON                   ;Assume command 7,
  1485.                JMP     SHORT CK_WRAP           ; turn line wrap on.
  1486.  
  1487. ;------------------------------------------------;
  1488.  
  1489. RESET_MODE:    MOV     AH,OFF                     ;Assume turn line wrap off.
  1490. CK_WRAP:       MOV     AL,BYTE PTR NUMBER_BUFFER  ;Retrieve number parameter.
  1491.                CMP     AL,7                       ;Is it 7?
  1492.                JZ      SET_WRAP                ;If yes, set wrap mode.
  1493.                JB      DO_MODE                 ;1 - 6 valid modes.
  1494.                CMP     AL,14                   ;14 - 16 valid modes.
  1495.                JB      MODE_END
  1496.                CMP     AL,19
  1497.                JA      MODE_END                ;If above 16, illegal.
  1498. DO_MODE:       XOR     AH,AH                   ;Else, set video mode
  1499.                INT     10H                     ; to parameter.
  1500.                RET
  1501.  
  1502. SET_WRAP:      MOV     LINE_WRAP,AH
  1503. MODE_END:      RET
  1504.  
  1505. ;--------------------------------------------------------------------;
  1506. ; Keyboard Key Reassignment:  First convert ASCII numbers to binary, ;
  1507. ; parse out delimiting semi-colons, and quote string delimiters.     ;
  1508. ;--------------------------------------------------------------------;
  1509.  
  1510. REASSIGNMENT:  TEST    STATUS,POFF             ;:If assignment are OFF,
  1511.                JZ      NOT_POFF                ;:   then exit as if
  1512.                JMP     ASSIGN_FLUSH            ;:   we are out of room.
  1513. NOT_POFF:                                      ;:
  1514.                MOV     CX,ESC_COUNT            ;Retrieve length of Esc sequence.
  1515.                DEC     CX                          ;Adjust.
  1516.                MOV     SI,OFFSET ESC_BUFFER + 2    ;Point past Esc, bracket.
  1517.                MOV     DI,OFFSET PARSE_BUFFER      ;Point to parse storage.
  1518. NEXT_STRING:   MOV     QUOTE_TYPE,0                ;Reset quote type.
  1519. NEXT_NUM:      XOR     DL,DL                   ;Use DL to carry number; init = 0
  1520.                XOR     BP,BP                   ;Use BP as number flag.
  1521. NEXT_PARAM:    LODSB                           ;Retrieve a byte.
  1522.                DEC     CX                      ;Decrement string length counter.
  1523.                JZ      PARSE_END               ;If zero, done.
  1524.                MOV     AH,QUOTE_TYPE           ;Else, retrieve quote type.
  1525.                OR      AH,AH                   ;If zero, not in string.
  1526.                JNZ     QUOTE_MODE              ;Else, go to string mode.
  1527.                CALL    CK_QUOTE                ;Is character a quote?
  1528.                JZ      NEXT_PARAM              ;If yes, ignore.
  1529.                CMP     AL,';'                  ;Else, is it semi-colon?
  1530.                JZ      STORE_NUMBER            ;If yes, number delimiter.
  1531.  
  1532.                SUB     AL,'0'                  ;Else, must be number; convert
  1533.                MOV     DH,AL                   ; to binary; save in DH.
  1534.                MOV     AX,10                   ;Multiply current total by ten.
  1535.                MUL     DL
  1536.                ADD     AL,DH                   ;Add new number.
  1537.                MOV     DL,AL                   ;Save in DL.
  1538.                MOV     BP,1                    ;Flag that number mode active.
  1539.                JMP     SHORT NEXT_PARAM        ;Next parameter.
  1540.  
  1541. STORE_NUMBER:  OR      BP,BP                   ;If number mode flag not set then
  1542.                JZ      NEXT_PARAM              ;semi-colon not prefaced with no.
  1543.                MOV     AL,DL                   ;Else, store number.
  1544.                STOSB
  1545.                JMP     SHORT NEXT_NUM          ;Reset number carrying registers.
  1546.  
  1547. QUOTE_MODE:    CMP     AL,AH                   ;Is current char a string ending
  1548.                JZ      NEXT_STRING             ; quote?  If yes, exit quote mode
  1549.                STOSB                           ;Else, store char as literal.
  1550.                JMP     SHORT NEXT_PARAM
  1551.  
  1552. ;----------------------------------------------------------------------------;
  1553. ; Remove duplicate assignments if removal leaves room for new assignment.    ;
  1554. ; If no duplicate and room, add new assignment, else flush buffer to screen. ;
  1555. ;----------------------------------------------------------------------------;
  1556.  
  1557. PARSE_END:     OR      BP,BP                   ;Was last parameter a number?
  1558.                JZ      CK_LENGTH               ;If no, skip.
  1559.                MOV     AL,DL                   ;Else, store the last number.
  1560.                STOSB
  1561. CK_LENGTH:     SUB     DI,OFFSET PARSE_BUFFER - 2   ;Calculate string length
  1562.                MOV     AX,DI                        ; including word for length.
  1563.                MOV     BX,WORD PTR PARSE_BUFFER     ;BL=new first ASCII; BH=2nd.
  1564.                MOV     CX,4                         ;String length has to be at
  1565.                OR      BL,BL                  ;+least word + 2 for old = 4
  1566.                JZ      CK_LEGAL                ; for extended key reassignment.
  1567.                DEC     CX                      ;And word + 1 for old = 3
  1568. CK_LEGAL:      CMP     AX,CX                   ; for regular ASCII reassignment.
  1569.                JB      ASSIGN_FLUSH            ;If not, illegal; flush buffer.
  1570.                JNE     DOCHK                   ;+If equal then unassign.
  1571.                XOR     AX,AX                   ;+
  1572. DOCHK:         MOV     BP,BUFFER_END           ;BP to carry buffer end pointer.
  1573.                CALL    CK_MATCH                ;Is char already reassigned?
  1574.                JC      CK_ROOM                 ;If no, check room for new.
  1575.  
  1576. CK_REMOVE:     MOV     CX,DX                   ;REASSIGN_END - string end
  1577.                SUB     CX,SI                   ; = bytes to move.
  1578.                JZ      CK_ROOM                 ;If zero, last string.
  1579.                SUB     DX,[DI]                 ;Is REASSIGN_END - old string
  1580.                ADD     DX,AX                   ; + new string >
  1581.                CMP     DX,BP                   ; BUFFER_END?
  1582.                JA      ASSIGN_FLUSH            ;If yes, flush buffer to screen.
  1583.                REP     MOVSB                   ;Else, move them down in buffer.
  1584.                JMP     SHORT STORE_NEW
  1585.  
  1586. CK_ROOM:       ADD     DX,AX                   ;New string + current strings.
  1587.                CMP     DX,BP                   ;Greater than buffer size?
  1588.                JA      ASSIGN_FLUSH            ;If yes, flush new string.
  1589. STORE_NEW:     MOV     SI,OFFSET PARSE_BUFFER  ;Else, room for new string.
  1590.                TEST    AX,255                  ;+Any reassign?
  1591.                JZ      NOREASG                 ;+no reassignment
  1592.                STOSW                           ;Store string length first.
  1593.                MOV     CX,AX                   ;Adjust counter.
  1594.                DEC     CX
  1595.                DEC     CX
  1596.                REP     MOVSB                   ;Store the actual string.
  1597. NOREASG:       MOV     REASSIGN_END,DI         ;+Store new string end.
  1598.                RET
  1599.  
  1600. ASSIGN_FLUSH:  CMP     AX,2                    ;+Any key number?
  1601.                JNE     FLUSHIN                 ;+no
  1602.                MOV     AX,OFFSET REASSIGNMENT_BUFFER
  1603.                MOV     REASSIGN_END,AX         ;+flush all reassigns.
  1604.                RET                             ;+
  1605. FLUSHIN:       MOV     AL,'p'                  ;+If buffer full, flush string
  1606.                JMP     FLUSH_BUFFER            ; including ending 'p' command.
  1607.  
  1608. ;------------------------------------------------------------------------------;
  1609. ; INPUT:  BL = first ASCII code to match; BH = extended if BL = 0              ;
  1610. ; OUTPUT: CY = 1 if no match found; CY = 0 if match found.                     ;
  1611. ;         DI points to string length of match; DI+2 points to start of string. ;
  1612. ;         SI = end of string; DX = REASSIGN_END; BP = BUFFER_END               ;
  1613. ;------------------------------------------------------------------------------;
  1614.  
  1615. CK_MATCH:      MOV     DX,REASSIGN_END                ;Current strings end.
  1616.                MOV     SI,OFFSET REASSIGNMENT_BUFFER  ;Point to buffer.
  1617. NEXT_MATCH:    MOV     DI,SI                          ;Current record.
  1618.                CMP     DI,DX                   ;End of strings?
  1619.                JAE     NO_MATCH                ;If yes, no match.
  1620.                MOV     CX,[DI+2]               ;CL=current first ASCII; CH=2nd
  1621.                ADD     SI,[DI]                 ;Point to next record.
  1622.                CMP     BL,CL                   ;First characters match?
  1623.                JNZ     NEXT_MATCH              ;If no, check next record.
  1624.                OR      BL,BL                   ;Extended code? ie zero.
  1625.                JNZ     MATCH                   ;If no, then match.
  1626.                CMP     BH,CH                   ;Else, check second code.
  1627.                JNZ     NEXT_MATCH              ;If not same, no match.
  1628. MATCH:         CLC                             ;Else return with CY = 0
  1629.                RET
  1630.  
  1631. NO_MATCH:      STC                             ;No match; CY = 1.
  1632.                RET
  1633.  
  1634. ;----------------------------------------------------------------------;
  1635. ; Buffer area will write over disposable data and initialization code. ;
  1636. ;----------------------------------------------------------------------;
  1637.  
  1638. ESC_BUFFER            =       $
  1639. NUMBER_BUFFER         =       ESC_BUFFER + ESC_BUFFER_SIZE
  1640. PARSE_BUFFER          =       NUMBER_BUFFER
  1641. DEVICE_STATUS_BUFFER  =       PARSE_BUFFER + ESC_BUFFER_SIZE
  1642. DEVICE_STATUS_SIZE    =       11
  1643. REASSIGNMENT_BUFFER   =       DEVICE_STATUS_BUFFER + DEVICE_STATUS_SIZE
  1644.  
  1645. ;              DISPOSABLE DATA
  1646. ;              ---------------
  1647.  
  1648. SYNTAX         LABEL   BYTE
  1649. DB      'Syntax:  ANSI [FAST | SLOW][ON | OFF][KON | KOFF][PON | POFF]'     ;^
  1650. if PCB                                           ;^
  1651. DB      '[XON | XOFF]'                           ;^
  1652. endif                                            ;^
  1653. DB      CR,LF ;:                                 ;^
  1654. DB      '              [/B nnn][/C][/Q][/U][/T][/S][/P n]',CR,LF ;. ;@      ;:
  1655. DB      'FAST     = direct screen writes; default',CR,LF                    ;:
  1656. DB      'SLOW     = screen writes via BIOS',CR,LF                           ;:
  1657. DB      'ON/OFF   = active/inactive; default is ON',CR,LF                   ;:
  1658. DB      'KON/KOFF = active/inactive reassignments; default is ON',CR,LF     ;:
  1659. DB      'PON/POFF = active/inactive NEW reassignments; default is ON',CR,LF ;:
  1660. if PCB                                           ;^
  1661. DB      'XON/XOFF = active/inactive @Xnn color codes; default is ON',CR,LF  ;^
  1662. endif                                            ;^
  1663. DB      'nnn = buffer size in bytes (0 - 60K) reserved for key reassignment; '
  1664. DB      'default 200',CR,LF
  1665. DB      '/Q  = Quiet, no output when executed',CR,LF                        ;:
  1666. DB      '/U  = Uninstall',CR,LF                                             ;:
  1667. DB      '/T  = Test if loaded',CR,LF                                        ;$
  1668. if PCB                                            ;$
  1669. DB      '/S  = Load stats from ANSICOM.SYS',CR,LF                           ;@
  1670. endif                                             ;$
  1671. DB      '/Pn = Protect n lines from scrolling at top'                       ;.
  1672. CR_LF   DB     CR,LF,LF,'$'
  1673.  
  1674. STATUS_MSG     DB      'Status: $'
  1675. BUFFER_MSG     DB      CR,LF,'Buffer size: $'
  1676. BYTES_FREE     DB      CR,LF,'Bytes free:  $'
  1677. ANSI_SYS_MSG   DB      'ANSI.SYS is installed so '
  1678. NOT_INSTALLED  DB      'ANSI.COM not installed',CR,LF,'$'
  1679. CON            DB      'CON'
  1680. CON_OFFSET     EQU     10
  1681. QUIET          DB      0                             ;| Quiet Mode
  1682. SYNTAX_FLAG    DB      0                             ;; Syntax Display Flag
  1683. TEST_FLAG      DW      0                             ;^ For report use
  1684.  
  1685. SIZE_MSG       DB      'Uninstall to change buffer size',CR,LF,LF,'$'
  1686. UNLOAD_MSG     DB      'ANSI can not be uninstalled',CR,LF
  1687.                DB      'Uninstall resident programs in reverse order',CR,LF,'$'
  1688. NOT_ENOUGH     DB      'Not enough memory',CR,LF,'$'
  1689. ALLOCATE_MSG   DB      'Memory allocation error',CR,LF,BELL,'$'
  1690. INSTALL_MSG    DB      'Installed',CR,LF,'$'
  1691. UNINSTALL_MSG  DB      'Uninstalled',CR,LF,'$'
  1692. if PCB                                            ;$
  1693. NO_FILE_MSG    DB      'ANSICOM.SYS not found',CR,LF,'$'                ;@
  1694. FILE_ERROR_MSG DB      'Error reading ANSICOM.SYS',CR,LF,'$'            ;@
  1695. FILE_NAME      DB      'ANSICOM.SYS',0                                  ;@
  1696. endif                                             ;$
  1697. alrdy_installed db      0                       ;^ Installed flag
  1698. other_seg       dw      0                       ;^ Segment of installed code
  1699. errmsg0         db      'Need DOS 2.0 or greater!$' ;^
  1700. errmsg14        db      'Error using Int 2Fh!$'     ;^
  1701.  
  1702. INITIALIZE     PROC    NEAR
  1703. ;--------------------------------------------------------------------;
  1704. ; Search memory for a copy of our code, to see if already installed. ;
  1705. ;--------------------------------------------------------------------;
  1706.  
  1707.                cld                             ;^
  1708.                mov     ah,30h                  ;^ Get DOS version
  1709.                int     21h                     ;^
  1710.                xchg    al,ah                   ;^ Swap major, minor numbers
  1711.                mov     dx,offset errmsg0       ;^ Bad DOS version
  1712.                cmp     ah,2                    ;^ Run if DOS 2.0 or greater.
  1713.                jb      jmp_msg_exit            ;^
  1714.                mov     dos_version,ax          ;^ Save version number
  1715. ;^
  1716. ;^ See if a copy is already resident in memory. If > DOS 3.0, use int 2Fh.
  1717. ;^
  1718.                mov     byte ptr [start+2],0    ;^ Initialize fingerprint
  1719.                cmp     dos_version,300h        ;^ See if DOS 3.0 or later
  1720.                jb      find_copy1              ;^ No, search the old way.
  1721.                mov     cx,16                   ;^ Try 16 different IDs.
  1722. find_copy:                                     ;^
  1723.                xor     ax,ax                   ;^
  1724.                mov     es,ax                   ;^
  1725.                mov     ah,multiplex_id         ;^ Load ID.  Use Int 2Fh to
  1726.                int     2fh                     ;^   reach installed code so
  1727.                or      al,al                   ;^   that we are compatible
  1728.                jne     find_copy0              ;^   with 386 memory managers.
  1729.                push    cs                      ;^
  1730.                pop     es                      ;^ If AL not changed, ALIAS not
  1731.                jmp     short find_copy4        ;^   installed.
  1732. find_copy0:                                    ;^
  1733.                push    cx                      ;^
  1734.                call    cmpheader               ;^ See if really Alias by
  1735.                pop     cx                      ;^   comparing file headers.
  1736.                je      find_copy3              ;^
  1737.                inc     multiplex_id            ;^ ID used by another program.
  1738.                loop    find_copy               ;^   Change and try again.
  1739.                mov     dx,offset errmsg14      ;^ All IDs taken, print error
  1740. jmp_msg_exit:  jmp     msg_exit                ;^   msg and exit.
  1741. ;
  1742. ;^ For DOS 2.x find the installed code the old fashioned way by scanning
  1743. ;^ the memory control blocks.
  1744. ;^
  1745. find_copy1:                                    ;^
  1746.                xor     bx,bx                   ;^ zero BX for start
  1747.                mov     ax,cs                   ;^ keep CS value in AX
  1748. find_copy2:                                    ;^
  1749.                inc     bx                      ;^ increment search segment value
  1750.                mov     es,bx                   ;^
  1751.                assume  es:nothing              ;^
  1752.                cmp     ax,bx                   ;^ not installed if current
  1753.                je      find_copy4              ;^   segment is found.
  1754.                call    cmpheader               ;^
  1755.                jne     find_copy2              ;^ loop back if not found
  1756. find_copy3:                                    ;^
  1757.                inc     alrdy_installed         ;^ Set installed flag
  1758. find_copy4:                                    ;^
  1759.                mov     other_seg,es            ;^ Save seg of installed code
  1760. ;^                CLD                             ;All string operations forward.
  1761. ;^                MOV     BX,OFFSET START         ;Point to start of code.
  1762. ;^                NOT     BYTE PTR [BX]           ;Change a byte so no false match.
  1763. ;^                XOR     DX,DX                   ;Start at segment zero.
  1764. ;^                MOV     AX,CS                   ;Store our segment in AX.
  1765. ;^ NEXT_PARAG:    INC     DX                      ;Next paragraph.
  1766. ;^                MOV     ES,DX
  1767. ;^                CMP     DX,AX                   ;Is it our segment?
  1768. ;^                JZ      ANNOUNCE                ;If yes, search is done.
  1769. ;^                MOV     SI,BX                   ;Else, point to our signature.
  1770. ;^                MOV     DI,BX                   ; and offset of possible match.
  1771. ;^                MOV     CX,16                   ;Check 16 bytes for match.
  1772. ;^                REP     CMPSB
  1773. ;^                JNZ     NEXT_PARAG              ;If no match, keep looking.
  1774.  
  1775. ;------------------------------------------------;
  1776.  
  1777. ANNOUNCE:                                      ;|
  1778.                MOV     SI,81H                  ;Point to command line.
  1779. NEXT_CAP:      LODSB                           ;Capitalize parameters.
  1780.                CMP     AL,CR
  1781.                JZ      PARSE
  1782.                CMP     AL,'a'
  1783.                JB      NEXT_CAP
  1784.                CMP     AL,'z'
  1785.                JA      NEXT_CAP
  1786.                AND     BYTE PTR [SI - 1],5FH
  1787.                JMP     SHORT NEXT_CAP
  1788.  
  1789. ;------------------------------------------------;
  1790.  
  1791. PARSE:         MOV     SI,81H                  ;Point to command line again.
  1792. NEXT_PARA:     XOR     AX,AX                   ;Position in status parameters.
  1793.                MOV     BX,4                    ;Status parameters each 4 bytes.
  1794. NEXT_STATUS:   MOV     DI,OFFSET PARAMETERS    ;Point to 'OFF ON  SLOWFAST'
  1795.                ADD     DI,AX                   ;Point to next parameter.
  1796.                ADD     AX,BX
  1797.                CMP     AX,LAST_PARAMETER       ;:Check all 8 possible statuses
  1798.                JA      CK_SWITCHES
  1799.                PUSH    SI                      ;Save command line pointer.
  1800.                MOV     CX,2                    ;Check first two bytes for match.
  1801.                CMP     AX,20                   ;: 3 Bytes for
  1802.                JB      Len_OK                  ;:   KON | KOFF | PON | POFF
  1803.                INC     CX                   ;: ;^   XON | XOFF
  1804. Len_OK:                                        ;:
  1805.                REP     CMPSB
  1806.                POP     SI                      ;Recover command line pointer.
  1807.                JNZ     NEXT_STATUS
  1808.  
  1809.                DIV     BL                      ;If match, divide offset by four.
  1810. ;:
  1811. ;:  Next 12 lines of routine changed
  1812. ;:
  1813. ;:             MOV     CL,1                    ;Set a bit to match offset.
  1814. ;:NEXT_SHIFT:  SHL     CL,1
  1815. ;:             DEC     AL
  1816. ;:             JNZ     NEXT_SHIFT
  1817. ;:             SHR     CL,1                    ;Adjust.
  1818. ;:             MOV     AH,STATUS_MASK          ;Retrieve appropriate ON/OFF
  1819. ;:             CMP     CL,ON                   ; or FAST/SLOW mask.
  1820. ;:             JBE     ADD_STATUS
  1821. ;:             ROL     AH,1
  1822. ;:             ROL     AH,1
  1823. ;:
  1824. ;:ADD_STATUS:  AND     ES:STATUS,AH            ;Mask off old status.
  1825. ;:             OR      ES:STATUS,CL            ;Add new status.
  1826. ;:
  1827.                MOV     CL,AL                ;: ;^ place count in CL (1 - 10)
  1828.                PUSH    DX                      ;^ Save Segment
  1829.                MOV     AX,AND_MASK          ;: ;^ Retrieve appropriate ON/OFF
  1830.                                                ;: FAST|SLOW|KON|KOFF|PON|POFF
  1831.                MOV     DX,OR_MASK              ;^ XON|XOFF
  1832.                DEC     CL                   ;: ;^ Make 1 - 10 into 0 - 9
  1833.                JZ      Skip_1                  ;: In position already if zero
  1834.                SHL     DX,CL                ;: ;^ Shift bit into position
  1835. Skip_1:        SHR     CL,1                    ;: divide count by 2
  1836.                JZ      Skip_2                  ;: Nevermind
  1837.                ROL     AX,CL                ;: ;^ Shift Mask into position
  1838.                ROL     AX,CL                ;: ;^
  1839. Skip_2:                                        ;:
  1840.  
  1841.                AND     ES:STATUS,AX            ;^ Mask off old status.
  1842.                OR      ES:STATUS,DX         ;: ;^ Add new status.
  1843.                POP     DX                      ;^ get back segment
  1844.                INC     SI                      ;Bump command line pointer.
  1845.                INC     SI
  1846.  
  1847. CK_SWITCHES:   LODSB                           ;Get a byte.
  1848.                CMP     AL,CR                   ;Is it carriage return?
  1849.                JNE     QUES                    ;$
  1850.                JMP     INSTALL                 ;If yes, done here.
  1851. QUES:          CMP     AL,'?'                  ;;Request for Syntax?
  1852.                JNE     CK_SW                   ;; No -
  1853.                MOV     BYTE PTR SYNTAX_FLAG, 1 ;; Yes-Show Syntax
  1854. CK_SW:         CMP     AL,'/'                  ;;Is there a switch character?
  1855.                JNE     NEXT_PARA               ;;If no, keep looking.
  1856. GOT_SWITCH:    LODSB                           ;;Else, get the switch character.
  1857.                CMP     AL,'B'                  ;Is it 'B' ?
  1858.                JNZ     CK_C                    ;If no, check 'C'.
  1859.                CALL    CK_INSTALLED            ;Else, see if already installed.
  1860.                JZ      GET_SIZE                ;If no, get buffer request size.
  1861.                MOV     DX,OFFSET SIZE_MSG      ;Else, display error message.
  1862.                CALL    PRINT_STRING
  1863. NEXT_PARA2:    JMP     SHORT NEXT_PARA
  1864. GET_SIZE:      CALL    DECIMAL_INPUT           ;Get number parameter.
  1865.                CMP     BX,REASSIGNMENT_MAX     ;If greater than maximum, use
  1866.                JBE     STORE_BUFFER            ; maximum, else use requested
  1867.                MOV     BX,REASSIGNMENT_MAX     ; size.
  1868. STORE_BUFFER:  MOV     REASSIGNMENT_SIZE,BX
  1869.                ADD     BX,OFFSET REASSIGNMENT_BUFFER  ;Calculate end of buffer.
  1870.                MOV     BUFFER_END,BX
  1871.                JMP     NEXT_PARA               ;;Too far for direct jump
  1872.  
  1873. CK_C:          CMP     AL,'C'                  ;Is it 'C' ?
  1874. if PCB                                         ;$
  1875.                JNZ     CK_S                    ;@ If not, check 'S'.
  1876. else                                           ;$
  1877.                JNZ     CK_P                    ;$ If not, check 'P'.
  1878. endif                                          ;$
  1879.                MOV     ES:REASSIGN_END,OFFSET REASSIGNMENT_BUFFER  ;Clear buffer
  1880.                JMP     NEXT_PARA               ;Else, next parmater.
  1881. if PCB                                         ;$
  1882. CK_S:          CMP     AL,'S'                  ;@ Is It 'S' ?
  1883.                JNZ     CK_P                    ;. If not, check 'P'.
  1884.                CALL    LOAD_STATS              ;@ Yes, Load Stats
  1885.                JMP     NEXT_PARA2              ;@ Next parameter (indirect)
  1886. endif                                          ;$
  1887. CK_P:          CMP     AL,'P'                  ;. Is it 'P' ?
  1888.                JNZ     CK_Q                    ;|If not, check 'Q'.
  1889.                CMP     BYTE PTR [SI], '*'      ;$Use current row-1?
  1890.                JNE     CK_PN                   ;$no
  1891.                PUSH    SI                      ;$Get
  1892.                CALL    GET_BIOS_DATA           ;$   current
  1893.                MOV     BL, ES:CURSOR_ROW       ;$          row
  1894.                DEC     BL                      ;$             -1
  1895.                POP     SI                      ;$
  1896.                JMP     CK_PS                   ;$
  1897. CK_PN:         CALL    DECIMAL_INPUT           ;. Get number of lines
  1898. CK_PS:         MOV     ES:START_SCROLL,BL      ;. Store the value
  1899.                JMP     NEXT_PARA2              ;. Next parameter (indirect)
  1900. CK_Q:          CMP     AL,'Q'                  ;|See if Quiet Mode
  1901.                JNE     CK_U                    ;|If not, check 'U'.
  1902.                NOT     QUIET                   ;|If yes turn on Quiet
  1903.                JMP     NEXT_PARA               ;Else, next parmater.
  1904. CK_U:          CMP     AL,'U'                  ;Is it 'U' ?
  1905.                JE      DO_U                    ;If yes, try to uninstall.
  1906.                CMP     AL,'T'                  ;; Test if Installed
  1907.                JE      DO_U
  1908.                MOV     BYTE PTR SYNTAX_FLAG, 1 ;; Syntax Error
  1909.                JMP     NEXT_PARA               ;Else, next parmater.
  1910.  
  1911. ;------------------------------------------------;
  1912.  
  1913. INSTALL:
  1914.                MOV     DX,OFFSET SIGNATURE     ;|Display our signature.
  1915.                CALL    PRINT_STRING            ;|
  1916.                CMP     BYTE PTR SYNTAX_FLAG,0  ;;Display Syntax?
  1917.                JE      SKIP_SYNTAX             ;;No
  1918.                MOV     DX,OFFSET SYNTAX        ;|Yes, Display syntax.
  1919.                CALL    PRINT_STRING            ;|
  1920. SKIP_SYNTAX:   CALL    STATUS_REPORT          ;;|Display status.
  1921.                CALL    CK_INSTALLED            ;Check if already installed.
  1922.                JZ      CK_AVAILABLE            ;If no, see if enough memory.
  1923.                XOR     AL,AL                   ;;Else, done.
  1924. EXIT2:         JMP     EXIT                    ;Exit with ERRORLEVEL = 0.
  1925.  
  1926. DO_U:          CALL    CK_INSTALLED            ;Else, see if installed.
  1927.                MOV     DX,OFFSET NOT_INSTALLED ;If no, exit with error message.
  1928.                JZ      LILLY_PAD               ;Too far for short jump.
  1929.                CMP     AL,'T'                  ;;Was it a test
  1930.                MOV     AX, STATUS              ;$return switches as ;^
  1931.                JE      EXIT2                   ;;$Yes Too far for short jump.
  1932.                JMP     UNINSTALL               ;$Else, uninstall.
  1933.  
  1934. ;--------------------------------;
  1935. ; This is the install procedure. ;
  1936. ;--------------------------------;
  1937.  
  1938. CK_AVAILABLE:  MOV     BP,OFFSET REASSIGNMENT_BUFFER   ;TSR ends at end
  1939.                ADD     BP,REASSIGNMENT_SIZE            ; of reassignment buffer.
  1940.                ADD     BP,15                           ;Round up.
  1941.                CMP     BP,DS:[6]               ;Buffer > PSP bytes in segment?
  1942.                MOV     DX,OFFSET NOT_ENOUGH    ;If yes, exit without installing
  1943.                JBE     CK_ANSI                 ;@
  1944. LILLY_PAD:     JMP     MSG_EXIT                ;@with message
  1945. CK_ANSI:       MOV     AX,3529H                ;@Get undocumented INT 29 vector.
  1946.                INT     21H
  1947.                MOV     SI,OFFSET CON           ;Does it point to ANSI.SYS?
  1948.                MOV     DI,CON_OFFSET           ;Check by looking for 'CON'
  1949.                MOV     CX,3                    ; as device name.
  1950.                REP     CMPSB
  1951.                MOV     DX,OFFSET ANSI_SYS_MSG  ;Exit with error message if
  1952.                JZ      LILLY_PAD               ;ANSI.SYS loaded.
  1953.  
  1954.                MOV     OLD_INT_29[0],BX        ;Else save old interrupt.
  1955.                MOV     OLD_INT_29[2],ES
  1956.                MOV     DX,OFFSET ANSI_INT_29   ;Install new interrupt.
  1957.                MOV     AX,2529H
  1958.                INT     21H
  1959.                MOV     AX,3516H                ;Get INT 16 vector.
  1960.                INT     21H
  1961.                MOV     OLD_INT_16[0],BX        ;Save old interrupt.
  1962.                MOV     OLD_INT_16[2],ES
  1963.                MOV     DX,OFFSET ANSI_INT_16   ;Install new interrupt.
  1964.                MOV     AX,2516H
  1965.                INT     21H
  1966.                MOV     AX,3521H                ;Get DOS 21h interrupt.
  1967.                INT     21H
  1968.                MOV     OLD_INT_21[0],BX        ;Save old interrupt.
  1969.                MOV     OLD_INT_21[2],ES
  1970.                MOV     DX,OFFSET ANSI_INT_21   ;Install new interrupt.
  1971.                MOV     AX,2521H
  1972.                INT     21H
  1973. if PCB                                            ;$
  1974.                MOV     AX,3508H                ;@ Get INT 08 vector.
  1975.                INT     21H                     ;@
  1976.                MOV     OLD_INT_08[0],BX        ;@ Save old interrupt.
  1977.                MOV     OLD_INT_08[2],ES        ;@
  1978.                MOV     DX,OFFSET ANSI_INT_08   ;@ Install new interrupt.
  1979.                MOV     AX,2508H                ;@
  1980.                INT     21H                     ;@
  1981. endif                                             ;$
  1982.                cmp     dos_version,300h        ;^ See if we are using Int 2Fh
  1983.                jb      install_3               ;^
  1984.                mov     ax,352fh                ;^ Get interrupt 2F (MUX)
  1985.                int     21h                     ;^  vector.
  1986.                mov     word ptr [int2fh],bx    ;^
  1987.                mov     word ptr [int2fh+2],es  ;^
  1988.                mov     ax,252fh                ;^ Point int 2F to internal
  1989.                mov     dx,offset muxint        ;^  routine.
  1990.                int     21h
  1991. Install_3:                                     ;^
  1992.  
  1993.                MOV     AX,DS:[2CH]             ;Get environment segment.
  1994.                MOV     ES,AX
  1995.                MOV     AH,49H                  ;Free up environment.
  1996.                INT     21H
  1997.  
  1998.                MOV     DX,OFFSET INSTALL_MSG   ;Display install message.
  1999.                CALL    PRINT_STRING
  2000.                CALL    FLUSH_END               ;Setup the number buffer.
  2001.                MOV     DX,BP                   ;Retrieve resident byte request.
  2002.                MOV     CL,4
  2003.                SHR     DX,CL                   ;Convert to paragraphs.
  2004.                MOV     AX,3100H                ;Return error code of zero.
  2005.                INT     21H                     ;Terminate but stay resident.
  2006.  
  2007. ;-------------------------------------------------------------------;
  2008. ; Exit.  Return ERRORLEVEL code 0 if successful, 1 if unsuccessful. ;
  2009. ;-------------------------------------------------------------------;
  2010.  
  2011. MSG_EXIT:      CALL    PRINT_STRING
  2012. ERROR_EXIT:    MOV     AL,1                    ;ERRORLEVEL = 1.
  2013. EXIT:          MOV     AH,4CH                  ;Terminate.
  2014.                INT     21H
  2015.  
  2016. ;^-----------------------------------------------------------------------------
  2017. ;^ CMPHEADER compares the first 16 bytes of this file with the segment
  2018. ;^           pointed to by ES.
  2019. ;^ Entry:  DS - code segment
  2020. ;^         ES - pointer to segment to compare
  2021. ;^ Exit:   ZF - 0 = segments match.
  2022. ;^-----------------------------------------------------------------------------
  2023. cmpheader      proc    near                    ;^
  2024.                mov     si,offset start+2       ;^ Search this segment for ASCII
  2025.                mov     di,si                   ;^   fingerprint.
  2026.                mov     cx,16                   ;^
  2027.                repe    cmpsb                   ;^
  2028.                ret                             ;^
  2029. cmpheader      endp                            ;^
  2030.  
  2031. ;---------------------------------------------------;
  2032. ; This subroutine uninstalls the resident ANSI.COM. ;
  2033. ;---------------------------------------------------;
  2034.  
  2035. UNINSTALL:     AND     ES:STATUS,NOT ON        ;Turn OFF ANSI, just in case
  2036.                OR      ES:STATUS,OFF           ; can't uninstall.
  2037.                MOV     CX,ES                   ;Save segment in CX.
  2038.                MOV     AX,3529H                ;Get interrupt 29h.
  2039.                INT     21H
  2040.                CMP     BX,OFFSET ANSI_INT_29   ;Has it been hooked by another?
  2041.                JNZ     UNINSTALL_ERR2          ;@If yes, exit with error message.
  2042.                MOV     BX,ES
  2043.                CMP     BX,CX                   ;Is the segment vector same?
  2044.                JNZ     UNINSTALL_ERR2          ;@If no, exit with error message.
  2045. if PCB                                         ;$
  2046.                MOV     AX,3508H                ;@Get interrupt 08h.
  2047.                INT     21H                     ;@
  2048.                CMP     BX,OFFSET ANSI_INT_08   ;@Has it been hooked by another?
  2049.                JNZ     UNINSTALL_ERR2        ;^;@If yes, exit with error message.
  2050.                MOV     BX,ES                   ;@
  2051.                CMP     BX,CX                   ;@Is the segment vector same?
  2052.                JNZ     UNINSTALL_ERR2        ;^;@If no, exit with error message.
  2053. endif                                          ;$
  2054.                MOV     AX,3516H                ;Get interrupt 16h.
  2055.                INT     21H
  2056.                CMP     BX,OFFSET ANSI_INT_16   ;Has it been hooked by another?
  2057.                JNZ     UNINSTALL_ERR           ;If yes, exit with error message.
  2058.                MOV     BX,ES
  2059.                CMP     BX,CX                   ;Is the segment vector same?
  2060. UNINSTALL_ERR2:JNZ     UNINSTALL_ERR           ;If no, exit with error message.
  2061.  
  2062.                MOV     AX,3521H                ;Get interrupt 21h.
  2063.                INT     21H
  2064.                CMP     BX,OFFSET ANSI_INT_21   ;Has it been hooked by another?
  2065.                JNZ     UNINSTALL_ERR           ;If yes, exit with error message.
  2066.                MOV     BX,ES
  2067.                CMP     BX,CX                   ;Is the segment vector same?
  2068.                JNZ     UNINSTALL_ERR           ;If no, exit with error message.
  2069.  
  2070.                MOV     AH,49H                  ;Return memory to system pool.
  2071.                INT     21H
  2072.                MOV     DX,OFFSET ALLOCATE_MSG
  2073.                JC      MSG_EXIT                ;Display message if problem.
  2074.  
  2075.                lds     dx,es:[int2fh]          ;^ Get old interrupt 2F vector
  2076.                cmp     dx,-1                   ;^ See if Int used
  2077.                je      remove_1                ;^ No, skip check of Int 2F
  2078.                mov     ax,252fh                ;^ Set interrupt
  2079.                int     21h                     ;^
  2080. remove_1:                                      ;^
  2081.                MOV     DX,ES:OLD_INT_29[0]     ;Restore old INT 29.
  2082.                MOV     DS,ES:OLD_INT_29[2]
  2083.                MOV     AX,2529H
  2084.                INT     21H
  2085. if PCB                                         ;$
  2086.                MOV     DX,ES:OLD_INT_08[0]     ;@Restore old INT 08.
  2087.                MOV     DS,ES:OLD_INT_08[2]     ;@
  2088.                MOV     AX,2508H                ;@
  2089.                INT     21H                     ;@
  2090. endif                                          ;$
  2091.                MOV     DX,ES:OLD_INT_16[0]     ;Restore old INT 16.
  2092.                MOV     DS,ES:OLD_INT_16[2]
  2093.                MOV     AX,2516H
  2094.                INT     21H
  2095.                MOV     DX,ES:OLD_INT_21[0]     ;Restore old INT 21.
  2096.                MOV     DS,ES:OLD_INT_21[2]
  2097.                MOV     AX,2521H
  2098.                INT     21H
  2099.  
  2100.                PUSH    CS
  2101.                POP     DS                      ;Point to our data.
  2102.                MOV     DX,OFFSET UNINSTALL_MSG ;Display uninstall message.
  2103.                CALL    PRINT_STRING
  2104.                OR      AL,AL                   ;Exit with ERRORLEVEL = 0.
  2105.                JMP     EXIT
  2106.  
  2107. UNINSTALL_ERR: MOV     ES,CX                   ;If error, display OFF status.
  2108.                CALL    STATUS_REPORT
  2109.                MOV     DX,OFFSET UNLOAD_MSG    ;And exit with error message.
  2110.                JMP     MSG_EXIT
  2111. INITIALIZE     ENDP
  2112.  
  2113. ;--------------------------------------------------;
  2114. ; INPUT:  SI points to parameter start.            ;
  2115. ; OUTPUT: SI points to parameter end; BX = number. ;
  2116. ;--------------------------------------------------;
  2117.  
  2118. DECIMAL_INPUT  PROC    NEAR
  2119.                XOR     BX,BX                   ;Start with zero as number.
  2120. NEXT_DECIMAL:  LODSB                           ;Get a character.
  2121.                CMP     AL,CR                   ;Carriage return?
  2122.                JZ      ADJUST_DEC              ;If yes, done here.
  2123.                CMP     AL,'/'                  ;Forward slash?
  2124.                JZ      ADJUST_DEC              ;If yes, done here.
  2125.                SUB     AL,'0'                  ;ASCII to binary.
  2126.                JC      NEXT_DECIMAL            ;If not between 0 and 9, skip.
  2127.                CMP     AL,9
  2128.                JA      NEXT_DECIMAL
  2129.                CBW                             ;Convert byte to word.
  2130.                XCHG    AX,BX                   ;Swap old and new number.
  2131.                MOV     CX,10                   ;Shift to left by multiplying
  2132.                MUL     CX                      ; last entry by ten.
  2133.                JC      DECIMAL_ERROR           ;If carry, too big.
  2134.                ADD     BX,AX                   ;Add new number and store in BX.
  2135.                JNC     NEXT_DECIMAL            ;If not carry, next number.
  2136. DECIMAL_ERROR: MOV     BX,-1                   ;Else, too big; return -1.
  2137.  
  2138. ADJUST_DEC:    DEC     SI                      ;Adjust pointer.
  2139.                RET
  2140. DECIMAL_INPUT  ENDP
  2141.  
  2142. ;-------------------------------------------------------;
  2143. ; OUTPUT: ZR = 1 if not installed; ZR = 0 if installed. ;
  2144. ;-------------------------------------------------------;
  2145.  
  2146. CK_INSTALLED:  PUSH    AX                      ;;
  2147.                MOV     AX,ES
  2148.                MOV     BX,CS
  2149.                CMP     AX,BX                   ;Compare segments.
  2150.                POP     AX                      ;;
  2151.                RET
  2152.  
  2153. ;------------------------------------------------;
  2154.  
  2155. STATUS_REPORT: MOV     DX,OFFSET STATUS_MSG
  2156.                CALL    PRINT_STRING            ;Display 'Status: '.
  2157.                MOV     BX,ES:STATUS            ;^ Status is now a Word
  2158.                MOV     TEST_FLAG,1             ;^ re-ran out of registers
  2159. NEXT_REPORT:   TEST    BX,TEST_FLAG            ;^ Check this status flag
  2160.                JZ      LOOP_STATUS
  2161.  
  2162.                MOV     DX,TEST_FLAG            ;^ We need a copy to play with
  2163. ;:
  2164. ;: Next 9 Lines changed
  2165. ;:
  2166. ;:             MOV     AX,-1
  2167. ;:NEXT_BIT:    INC     AX
  2168. ;:             SHR     DL,1
  2169. ;:             JNC     NEXT_BIT
  2170. ;:             SHL     AX,1
  2171. ;:             SHL     AX,1
  2172. ;:             MOV     SI,OFFSET PARAMETERS    ;Display appropriate ON or OFF,
  2173. ;:             ADD     SI,AX                   ; SLOW or FAST.
  2174. ;:             MOV     CX,4
  2175. ;:
  2176.                MOV     SI,OFFSET PARAMETERS    ;:Display appropriate ON or OFF,
  2177.                                                ;: SLOW|FAST.  KON|KOFF|PON|POFF
  2178.                MOV     CX,4                    ;:Each four characters long
  2179. NEXT_BIT:      SHR     DX,1                 ;: ;^Is this our Word?
  2180.                JC      REPORT                  ;:Yes - Print it
  2181.                ADD     SI,CX                   ;:No  - Skip over it
  2182.                JMP     NEXT_BIT                ;:test the next bit
  2183. REPORT:        LODSB
  2184.                CALL    PRINT_CHAR
  2185.                LOOP    REPORT
  2186.                MOV     AL, ' '                 ;: Space words
  2187.                CALL    PRINT_CHAR              ;:
  2188.  
  2189. LOOP_STATUS:   SHL     TEST_FLAG,1             ;^
  2190.                TEST    TEST_FLAG,03FFH         ;^
  2191.                JNZ     NEXT_REPORT          ;: ;^ Check all 10 bits
  2192.                                                ;:
  2193.                MOV     DX,OFFSET BUFFER_MSG    ;Display 'Buffer size: '.
  2194.                CALL    PRINT_STRING
  2195.                MOV     AX,ES:REASSIGNMENT_SIZE
  2196.                PUSH    AX
  2197.                XOR     BP,BP
  2198.                CALL    DECIMAL_OUT             ;Display the size.
  2199.                MOV     DX,OFFSET BYTES_FREE    ;Display 'Bytes free: '.
  2200.                CALL    PRINT_STRING
  2201.                POP     AX
  2202.                ADD     AX,OFFSET REASSIGNMENT_BUFFER
  2203.                SUB     AX,ES:REASSIGN_END
  2204.                CALL    DECIMAL_OUT             ;Display the bytes free.
  2205.                MOV     DX,OFFSET CR_LF
  2206.                CALL    PRINT_STRING
  2207.                RET
  2208.  
  2209. ;------------------------------------------------;
  2210.  
  2211. PRINT_CHAR:    MOV     DL,AL
  2212.                MOV     AH,2                    ;Print character via DOS.
  2213.                OR      AL,AL                   ;:Skip NULLs
  2214.                JNZ     SHORT DOS_INT           ;:
  2215.                RET                             ;:
  2216.  
  2217. PRINT_STRING:  MOV     AH,9                    ;Print string via DOS.
  2218. DOS_INT:       CMP     QUIET,0                 ;|Do we suppress output
  2219.                JNE     NO_PRINT                ;|Yes
  2220.                INT     21H                     ;|No
  2221. NO_PRINT:                                      ;|
  2222.                RET
  2223. if PCB                                         ;$
  2224. LOAD_STATS:    MOV    DX,OFFSET FILE_NAME      ;@ Stat filename
  2225.                MOV    AX,3D00H                 ;@ Open File
  2226.                INT    21H                      ;@ DOS Interupt
  2227.                MOV    DX,OFFSET NO_FILE_MSG    ;@ Assume no file
  2228.                JNC    OPEN_OK                  ;@ Ok, So far
  2229. MSG_EXIT2:     JMP    MSG_EXIT                 ;@ No file found probably
  2230. OPEN_OK:       MOV    BX,AX                    ;@ This is our Handle number
  2231.                PUSH   DS                       ;@ Save DS
  2232.                PUSH   ES                       ;@ Set ES to DS
  2233.                POP    DS                       ;@
  2234.                MOV    DX, OFFSET SUB_LIST      ;@ Point to the Sub_List
  2235.                MOV    CX, SUB_LENGTH           ;@ Get the Length ot the List
  2236.                MOV    AH,3FH                   ;@ Read from Handle
  2237.                INT    21H                      ;@ DOS Interupt
  2238.                POP    DS                       ;@ Restore DS
  2239.                PUSHF                           ;@ Save results
  2240.                PUSH   AX                       ;@
  2241.                MOV    AH,3EH                   ;@ Close Handle
  2242.                INT    21H                      ;@ DOS Interupt
  2243.                POP    AX                       ;@ Restore results
  2244.                POPF                            ;@
  2245.                MOV    DX,OFFSET FILE_ERROR_MSG ;@ Assume an error occured
  2246.                JC     MSG_EXIT2                ;@ Yep, it did
  2247.                XCHG   AX,CX                    ;@ Swap Bytes Read
  2248.                JCXZ   MSG_EXIT2                ;@ Something went wrong
  2249.                CMP    AX,CX                    ;@ Did we read the full amount
  2250.                JNE    MSG_EXIT2                ;@ No
  2251.                RET                             ;@ All went well!
  2252. endif                                          ;$
  2253. _TEXT          ENDS
  2254.                END     START
  2255.